81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace IOB_MAN
|
|
{
|
|
public partial class AutoClosingMessageBox : Form
|
|
{
|
|
#region Public Constructors
|
|
|
|
public AutoClosingMessageBox(string message, string caption, int timeoutSeconds)
|
|
{
|
|
_baseMessage = message;
|
|
_secondsRemaining = timeoutSeconds;
|
|
|
|
// Configurazione Form
|
|
this.Text = caption;
|
|
this.Size = new Size(450, 200);
|
|
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
this.StartPosition = FormStartPosition.CenterScreen;
|
|
this.MaximizeBox = false;
|
|
this.MinimizeBox = false;
|
|
|
|
// Configurazione Label (Testo Grande)
|
|
_lblMessage = new Label();
|
|
_lblMessage.Dock = DockStyle.Fill;
|
|
_lblMessage.TextAlign = ContentAlignment.MiddleCenter;
|
|
_lblMessage.Font = new Font("Segoe UI", 12F, FontStyle.Regular); // Testo più grande
|
|
_lblMessage.Padding = new Padding(10);
|
|
this.Controls.Add(_lblMessage);
|
|
|
|
UpdateLabelText();
|
|
|
|
// Configurazione Timer (scatta ogni secondo)
|
|
_timer = new System.Windows.Forms.Timer();
|
|
_timer.Interval = 1000;
|
|
_timer.Tick += Timer_Tick;
|
|
_timer.Start();
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Private Fields
|
|
|
|
private string _baseMessage;
|
|
private Label _lblMessage;
|
|
private int _secondsRemaining;
|
|
private System.Windows.Forms.Timer _timer;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
{
|
|
_secondsRemaining--;
|
|
if (_secondsRemaining <= 0)
|
|
{
|
|
_timer.Stop();
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
UpdateLabelText();
|
|
}
|
|
}
|
|
|
|
private void UpdateLabelText()
|
|
{
|
|
_lblMessage.Text = $"{_baseMessage}\n\nQuesta finestra si chiuderà tra {_secondsRemaining} secondi.";
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |