Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to overwrite <code>ShowDialog()</code> and <code>ShowDialog(owner)</code>. When your show dialog will be called you start a timer and forward to the <code>base.ShowDialog()</code>. When the timer raises the tick event simply call <code>Close()</code>.</p> <p>Here an example implementation:</p> <pre><code>public partial class FormTimed : Form { private String _OriginalText; private DateTime _StartTime; private Timer _Timer; public FormTimed() { InitializeComponent(); InitializeTimer(); Duration = TimeSpan.FromSeconds(10); } [DefaultValue(typeof(TimeSpan), "00:00:10")] public TimeSpan Duration { get; set; } public override string Text { get { return _OriginalText; } set { _OriginalText = value; base.Text = value; } } public void DisableTimer() { _Timer.Stop(); base.Text = _OriginalText; } public void ResetTimer() { _StartTime = DateTime.UtcNow; _Timer.Start(); } public new DialogResult ShowDialog() { StartTimer(); return base.ShowDialog(); } public new DialogResult ShowDialog(IWin32Window owner) { StartTimer(); return base.ShowDialog(owner); } private void InitializeTimer() { _Timer = new Timer(); _Timer.Interval = 100; _Timer.Tick += OnTimerTick; } private void OnTimerTick(object sender, EventArgs e) { var finishTime = _StartTime + Duration; var remainingDuration = finishTime - DateTime.UtcNow; if (remainingDuration &lt; TimeSpan.Zero) { Close(); } base.Text = _OriginalText + " (" + (int)remainingDuration.TotalSeconds + ")"; } private void StartTimer() { _StartTime = DateTime.UtcNow; _Timer.Start(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload