Login Register






[VB6, VB.NET] [Source] Meter control - Draw angle-based lines filter_list
Author
Message
[VB6, VB.NET] [Source] Meter control - Draw angle-based lines #1
Example: Analog Clock

[Image: Clock.gif]

I wanted to make this a few weeks ago. But couldn't get how can I.
Then yesterday I was just drawing random stuff by lines in VB then this idea came to my mind.

I know the length of lines are not consistent, it's like they are drawn in a rhombus. But I'll figure it out someday.

VB.NET
Code:
Dim G As Drawing.Graphics Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load G = PictureBox1.CreateGraphics End Sub Private Sub Meter(ByVal sPic As PictureBox, ByVal Value As Integer, ByVal Pen As Pen) 'Meter control 1.0 'Made on 29th October 2010, by Coder 'Don't delete this please. Dim CenterX As Long, CenterY As Long 'G.Clear(sPic.BackColor) 'Commented for multi-meters CenterX = sPic.Width / 2 CenterY = sPic.Height / 2 If Value >= 180 Then Value = 179 'Making sure our Angle does not exceed what we want If Value <= 45 Then G.DrawLine(Pen, CenterX, CenterY, CenterX + Value, Value) ElseIf Value > 45 And Value <= 90 Then G.DrawLine(Pen, CenterX, CenterY, CenterX + (90 - Value), Value) ElseIf Value > 90 And Value <= 135 Then G.DrawLine(Pen, CenterX, CenterY, CenterX - (Value - 90), (CenterY * 2) - (Value - 90)) ElseIf Value > 135 And Value < 180 Then G.DrawLine(Pen, CenterX, CenterY, Value - 135, CenterY - (Value - 135)) End If End Sub

Usage: (for Clock)
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick G.Clear(PictureBox1.BackColor) Meter(PictureBox1, CInt(TimeOfDay.Second) * 3, Pens.Gray) Meter(PictureBox1, CInt(TimeOfDay.Minute) * 3, Pens.Black) If CInt(TimeOfDay.Hour) > 12 Then Meter(PictureBox1, CInt((TimeOfDay.Hour - 12)) * 15, Pens.Blue) Else Meter(PictureBox1, CInt(TimeOfDay.Hour) * 15, Pens.Blue) End Sub



VB6
Code:
Private Sub Meter(sPic As PictureBox, Value As Integer, Color As Long) 'Meter control 1.0 'Made on 29th October 2010, by Coder 'Don't delete this please. Dim CenterX As Long, CenterY As Long 'sPic.Cls 'Commented for multi-meters CenterX = sPic.ScaleWidth / 2 CenterY = sPic.ScaleHeight / 2 If Value >= 180 Then Value = 179 'Making sure our Angle does not exceed what we want If Value <= 45 Then sPic.Line (CenterX, CenterY)-(CenterX + Value, Value), Color ElseIf Value > 45 And Value <= 90 Then sPic.Line (CenterX, CenterY)-(CenterX + (90 - Value), Value), Color ElseIf Value > 90 And Value <= 135 Then sPic.Line (CenterX, CenterY)-(CenterX - (Value - 90), (CenterY * 2) - (Value - 90)), Color ElseIf Value > 135 And Value < 180 Then sPic.Line (CenterX, CenterY)-(Value - 135, CenterY - (Value - 135)), Color End If End Sub

Usage: (For Clock)
Code:
Private Sub Timer1_Timer() GetTime End Sub Sub GetTime() Picture1.Cls Meter Picture1, CInt(DateTime.Second(DateTime.Time) * 3), RGB(160, 160, 160) Meter Picture1, CInt(DateTime.Minute(DateTime.Time) * 3), RGB(100, 180, 100) Meter Picture1, CInt(DateTime.Hour(DateTime.Time) * 15), RGB(40, 40, 40) Me.Caption = DateTime.Now End Sub

Download link for Clock executable (if anybody is interested)

I hope you like it. Give credits if you use. Smile
[Image: rytwG00.png]
Redcat Revolution!

Reply