128 lines
3 KiB
C#
128 lines
3 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Speech.Synthesis;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ControlApp;
|
|
|
|
public class CustomMessage : Form
|
|
{
|
|
private string msg;
|
|
|
|
private string btn;
|
|
|
|
private int time;
|
|
|
|
private bool ttspeech;
|
|
|
|
private Timer tmr;
|
|
|
|
private IContainer components;
|
|
|
|
private Label label1;
|
|
|
|
private Button button1;
|
|
|
|
public CustomMessage(string message, string button, int timeopen, bool tts)
|
|
{
|
|
InitializeComponent();
|
|
msg = message;
|
|
btn = button;
|
|
ttspeech = tts;
|
|
time = timeopen;
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void CustomMessage_Load(object sender, EventArgs e)
|
|
{
|
|
if (ttspeech)
|
|
{
|
|
base.Opacity = 0.0;
|
|
SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
|
|
speechSynthesizer.SetOutputToDefaultAudioDevice();
|
|
speechSynthesizer.Speak(msg);
|
|
speechSynthesizer.Dispose();
|
|
try
|
|
{
|
|
Close();
|
|
return;
|
|
}
|
|
catch
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
label1.Text = msg;
|
|
if (btn != "")
|
|
{
|
|
button1.Text = btn;
|
|
}
|
|
if (time != 0)
|
|
{
|
|
tmr = new Timer();
|
|
tmr.Tick += delegate
|
|
{
|
|
Close();
|
|
};
|
|
tmr.Interval = (int)TimeSpan.FromSeconds(time).TotalMilliseconds;
|
|
tmr.Start();
|
|
}
|
|
}
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing && components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.label1 = new System.Windows.Forms.Label();
|
|
this.button1 = new System.Windows.Forms.Button();
|
|
base.SuspendLayout();
|
|
this.label1.AutoSize = true;
|
|
this.label1.Font = new System.Drawing.Font("Segoe UI", 25f, System.Drawing.FontStyle.Bold);
|
|
this.label1.Location = new System.Drawing.Point(26, 24);
|
|
this.label1.MaximumSize = new System.Drawing.Size(800, 0);
|
|
this.label1.Name = "label1";
|
|
this.label1.Size = new System.Drawing.Size(117, 46);
|
|
this.label1.TabIndex = 0;
|
|
this.label1.Text = "label1";
|
|
this.label1.Click += new System.EventHandler(label1_Click);
|
|
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
|
|
this.button1.AutoSize = true;
|
|
this.button1.Location = new System.Drawing.Point(244, 81);
|
|
this.button1.Name = "button1";
|
|
this.button1.Size = new System.Drawing.Size(75, 25);
|
|
this.button1.TabIndex = 1;
|
|
this.button1.Text = "Close";
|
|
this.button1.UseVisualStyleBackColor = true;
|
|
this.button1.Click += new System.EventHandler(button1_Click);
|
|
base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 15f);
|
|
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
this.AutoSize = true;
|
|
base.ClientSize = new System.Drawing.Size(563, 118);
|
|
base.ControlBox = false;
|
|
base.Controls.Add(this.button1);
|
|
base.Controls.Add(this.label1);
|
|
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
|
base.Name = "CustomMessage";
|
|
this.Text = "CustomMessage";
|
|
base.TopMost = true;
|
|
base.Load += new System.EventHandler(CustomMessage_Load);
|
|
base.ResumeLayout(false);
|
|
base.PerformLayout();
|
|
}
|
|
}
|