///
<summary>
/// Summary
description for AControl.
///
</summary>
[Designer(typeof(AControlDesigner))]
//associate the designer with the control
public class
AControl : Control
{
private
TimeSpan _usableTime;
///
<summary>
///
The period of time after which the control will become unusable
///
</summary>
public
TimeSpan UsableTime
{
get
{
return
_usableTime;
}
set
{
_usableTime
= value;
EnableTimeout=EnableTimeout;
}
}
Timer
TimeoutTimer;
bool
_enableTimeout;
///
<summary>
///
The control will time out and become unusable after a period of time
///
</summary>
public
bool EnableTimeout
{
get
{
return
_enableTimeout;
}
set
{
_enableTimeout=value;
if
(TimeoutTimer!=null)
TimeoutTimer.Dispose();
if(value
&& this._usableTime>new
TimeSpan(0,0,0,0,0))
{
TimeoutTimer=new Timer();
TimeoutTimer.Interval=(int)_usableTime.TotalMilliseconds;
TimeoutTimer.Tick+=new
EventHandler(TimeoutTimer_Tick);
TimeoutTimer.Enabled=true;
}
}
}
public
AControl()
{
//Because
the BackColor is always PowderBlue the BackColor property must be removed.
this.BackColor=Color.PowderBlue;
}
private
void TimeoutTimer_Tick(object
sender, EventArgs e)
{
TimeoutTimer.Enabled=false;
this.Enabled=false;
Invalidate();
}
protected
override void
OnPaint(PaintEventArgs e)
{
if
(this.Enabled==false)
{
e.Graphics.DrawLine(Pens.Red,0,0,this.Width,this.Height);
e.Graphics.DrawLine(Pens.Red,this.Width,0,0,this.Height);
}
base.OnPaint
(e);
}
}
The control with a timeout.
Imports
System
Imports
System.ComponentModel
Imports
System.ComponentModel.Design
Imports
System.Windows.Forms
Imports
System.Windows.Forms.Design
Imports
System.Drawing
Namespace
WellFormed
'/ <summary>
'/ Summary description for AControl.
'/ </summary>
<Designer(GetType(AControlDesigner))>
_
Public Class
AControl 'associate the designer with the control
Inherits
Control
Private
_usableTime As TimeSpan
'/
<summary>
'/
The period of time after which the control will become unusable
'/
</summary>
Public
Property UsableTime()
As TimeSpan
Get
Return
_usableTime
End
Get
Set
_usableTime = value
EnableTimeout = EnableTimeout
End
Set
End
Property
Private
TimeoutTimer As Timer
Private
_enableTimeout As
Boolean
'/
<summary>
'/
The control will time out and become unusable after a period of time
'/
</summary>
Public
Property EnableTimeout()
As Boolean
Get
Return
_enableTimeout
End
Get
Set
_enableTimeout
= value
If
Not (TimeoutTimer Is
Nothing) Then
TimeoutTimer.Dispose()
End
If
If
Value AndAlso Me._usableTime.CompareTo(New
TimeSpan(0, 0, 0, 0, 0)) > 0 Then
TimeoutTimer = New Timer
TimeoutTimer.Interval = CInt(_usableTime.TotalMilliseconds)
AddHandler
TimeoutTimer.Tick, AddressOf TimeoutTimer_Tick
TimeoutTimer.Enabled = True
End
If
End
Set
End
Property
Public
Sub New()
'Because
the BackColor is always PowderBlue the BackColor property must be removed.
Me.BackColor
= Color.PowderBlue
End
Sub 'New
Private
Sub TimeoutTimer_Tick(sender
As Object, e
As EventArgs)
TimeoutTimer.Enabled = False
Me.Enabled
= False
Invalidate()
End
Sub 'TimeoutTimer_Tick
Protected
Overrides Sub
OnPaint(e As PaintEventArgs)
If
Me.Enabled = False
Then
e.Graphics.DrawLine(Pens.Red, 0, 0, Me.Width,
Me.Height)
e.Graphics.DrawLine(Pens.Red, Me.Width, 0,
0, Me.Height)
End
If
MyBase.OnPaint(e)
End
Sub 'OnPaint
End Class
'AControl