|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionMy first intention was to build a Windows Control like
that one you can see in Windows Task Manager which goes with Windows2000.
Considering that is the really simple control, I decided to add a few things to
improve it a little bit. You can use this control to visually track down any
variable in your program linking it with control's Added PropertiesI wrote a few properties to provide additional capabilities of the control:
Drawing The ControlThe code required for drawing the control is located in two methods: Protected Overrides Sub OnPaintBackground(ByVal pevent As _
System.Windows.Forms.PaintEventArgs)
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
I used 'Grid lines
For i = 1 To CInt(Me.Height / mGrid)
e.Graphics.DrawLine(Pens.DarkGreen, 0, i * mGrid, Me.Width, i * mGrid)
Next i
For i = 1 To CInt(Me.Width / mGrid)
e.Graphics.DrawLine(Pens.DarkGreen, i * mGrid - mover, 0,
i * mGrid - mover, Me.Height)
Next i
'Values
For i = 1 To values.Count - 1
If CInt(values(i)) Me.UpperRange Or CInt(values(i)) Me.LowerRange Then
e.Graphics.DrawLine(Pens.Red, Me.Width - intDivision * (values.Count - i), _
CInt(Me.Height * (Me.Maximum - CInt(values(i))) / (Me.Maximum - Me.Minimum)), _
Me.Width - intDivision * (values.Count - i + 1), _
CInt(Me.Height * (Me.Maximum - CInt(values(i - 1))) / (Me.Maximum - Me.Minimum)))
Else
e.Graphics.DrawLine(Pens.Yellow, Me.Width - intDivision * (values.Count - i), _
CInt(Me.Height * (Me.Maximum - CInt(values(i))) / (Me.Maximum - Me.Minimum)), _
Me.Width - intDivision * (values.Count - i + 1), _
CInt(Me.Height * (Me.Maximum - CInt(values(i - 1))) / (Me.Maximum - Me.Minimum)))
End If
Next i
'Control's border
ControlPaint.DrawBorder3D(e.Graphics, 0, 0, Width, Height, Border3DStyle.Sunken)
To redraw the control in certain interval of time I used
a thread and started it in the constructor of the control using thread's To fully enable double-buffering, you must set the Private otter As New ThreadStart(AddressOf MyThreadProc)
Private oThread As New Thread(otter)
Design-Time AttributesBecause components can be displayed in a designer, such
as Visual Studio .NET, they require attributes that provide metadata to
design-time tools. Every property which I added to the control has a few
attributes in order to better describe a component to the user. To simplify
finding the added properties of the control you should specify the category in
which the property (or event) will be displayed in a visual designer. You can do
that with Demo ApplicationTo show how the control behaves on the form you can open
new Windows Application Project, add it to the ToolBox (Tracker.dll) and
double-click icon in the ToolBar with name Tracker ( For a practical purpose of this demo I added only a TrackBar on the form and adjusted its property Me.Tracker1.Value = Me.TrackBar1.Value
Run the application and good luck ! CommentI have created this control in VB.NET Standard Edition which comes without Component Designer. It's good idea to add a test project (Windows Application) to existing solution in order to test control's behaviour on the form. As soon as you compile your control, all changes are visible in design mode of your test form. I have tested the control only in Windows2000, and there is no reason that it shouldn't be working in other versions of Windows starting with Win98 as indicated in Microsoft .NET documentation.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||