Eine Uhr mit zeiger proggen?

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von Poapfel.

    Eine Uhr mit zeiger proggen?

    hay

    habe mal ne frage im bezug auf diesen code:

    VB.NET-Quellcode

    1. Public Class frmZeiger
    2. Public MiddlePoint As New PointF(150, 150)
    3. Public MainRadius As Integer = 100
    4. Public Drehwinkel As Decimal = 0
    5. Public Value As Single = 0
    6. Private Direction As Boolean
    7. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    8. With e.Graphics
    9. .SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
    10. Dim PenBlack As New Pen(Color.Black, 4)
    11. Dim NeedleEnd As New PointF(MiddlePoint.X - MainRadius * Math.Sin(Drehwinkel), MiddlePoint.Y - MainRadius * Math.Cos(Drehwinkel))
    12. .DrawLine(PenBlack, MiddlePoint, NeedleEnd)
    13. End With
    14. End Sub
    15. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    16. If Value >= 0 Then
    17. Direction = True
    18. ElseIf Value < 0 Then
    19. Direction = False
    20. End If
    21. If Direction = True Then
    22. Value += 0.5
    23. ElseIf Direction = False Then
    24. Value -= 0.5
    25. End If
    26. Drehwinkel = (2 * Math.PI) / 1100 * Value
    27. Invalidate()
    28. End Sub
    29. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    30. Timer1.Enabled = True
    31. End Sub
    32. End Class

    ist es möglich mit diesem code eine uhr zu proggen?
    Und wenn ja wie geh das?
    In diesem code geht der zeiger gegen den uhrzeigersinn...

    hoff auf antwort

    Habe den Code aus dem Internet: spsforen.com/showthread.php?t=26816
    da wird gesagt das der n steuer instrument haben will aber ich wollt ne uhr mit drei zeigern erstellen(wie jede normale uhr halt^^)
    Du benötigst einen Timer und eine PictureBox. Zieh einen
    Timer und eine PictureBox einfach aus der ToolBox auf die Form und
    passe die Größe der PictureBox an. Und schreibe in die Form_Load Methode
    folgendes hinein:

    VB.NET-Quellcode

    1. Timer1.Start


    Dann müsste es gehen.

    Gruss
    Hastling

    Shaymin123[CRI09] schrieb:

    habs versucht aber stretch image funzt net
    kann die jemand auf die hälfte umschreiben
    habs versucht aber dann sind keine zahlen da und zeiger unten und rahmen links und so weiter

    bedank mich schonmal

    stimmt doch gar nicht
    du musst die eigenschaft "SizeMode" der picturebox auf "StretchImage" stellen und dann kannst du die größe der picturebox nach belieben verändern ;)
    stimmt doch gar nicht
    du musst die eigenschaft "SizeMode" der picturebox auf "StretchImage" stellen und dann kannst du die größe der picturebox nach belieben verändern;)

    oh ich ging davon aus das ich bei BackgroundImageLayout da Stretch einstellen musste :(
    aber der tip is jut danke^^
    Let's add the code for the Form Load event: Add the following highlighted code:
    Code:

    VB.NET-Quellcode

    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2. ' Locate the clock numbers on the screen:
    3. Label1.Location = New Point(505, 203)
    4. Label2.Location = New Point(561, 261)
    5. Label3.Location = New Point(592, 335)
    6. Label4.Location = New Point(561, 404)
    7. Label5.Location = New Point(505, 464)
    8. Label6.Location = New Point(430, 489)
    9. Label7.Location = New Point(357, 463)
    10. Label8.Location = New Point(305, 408)
    11. Label9.Location = New Point(272, 334)
    12. Label10.Location = New Point(302, 259)
    13. Label11.Location = New Point(354, 200)
    14. Label12.Location = New Point(430, 177)
    15. End Sub


    __________________________________________________ ____________


    Then add the following highlighted declarations to the code:
    Code:

    VB.NET-Quellcode

    1. Public Class Form1
    2. ' tick will be used to draw 60 marks for each second on the clock
    3. Dim tick As Integer = 270
    4. 'tick2 will be used to draw 12 bold marks on each hour on the clock
    5. Dim tick2 As Integer = 270


    __________________________________________________ ______________


    Then double click on timer1 and add the following highlighted code:

    Code:

    VB.NET-Quellcode

    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. 'timer1 will draw the hands of the clock
    3. 'convert seconds to angles
    4. Dim seconds As Integer = (Now.Second * 6) + 270
    5. 'convert minutes to angles
    6. Dim minutes As Integer = (Now.Minute * 6) + 270
    7. 'convert hours to angles
    8. Dim hours As Integer = (Now.Hour * 30) + 270
    9. 'text label will hold the current time
    10. Time.Text = Now
    11. 'creating graphics
    12. Dim g As Graphics
    13. g = Me.CreateGraphics
    14. 'creating pens
    15. Dim hour As New Pen(Color.Blue)
    16. Dim hour2 As New Pen(Color.White)
    17. Dim second As New Pen(Color.Black)
    18. Dim minute As New Pen(Color.Red)
    19. Dim minute2 As New Pen(Color.White)
    20. Dim white As New Pen(Color.White)
    21. Dim circle As New Pen(Color.Black)
    22. 'assigning pens width
    23. hour.Width = 8
    24. hour2.Width = 10
    25. second.Width = 1
    26. minute.Width = 4
    27. minute2.Width = 4
    28. white.Width = 10
    29. circle.Width = 5
    30. 'drawing the hands of the clock and their locations
    31. g.DrawPie(hour2, 319, 219, 240, 240, hours - 30, 360)
    32. g.DrawPie(minute2, 289, 189, 300, 300, minutes - 6, 360)
    33. g.DrawPie(Pens.White, 269, 169, 340, 340, seconds - 6, 360)
    34. g.DrawPie(hour, 319, 219, 240, 240, hours, 360)
    35. g.DrawEllipse(white, 319, 219, 240, 240)
    36. g.DrawPie(minute, 289, 189, 300, 300, minutes, 360)
    37. g.DrawEllipse(white, 289, 189, 300, 300)
    38. g.DrawPie(second, 269, 169, 340, 340, seconds, 360)
    39. g.DrawEllipse(white, 269, 169, 340, 340)
    40. 'Draw a circle around the clock
    41. g.DrawEllipse(circle, 249, 149, 380, 380)
    42. End Sub

    __________________________________________________ ______________


    Then double click on Timer2 and add the following highlighted code:


    Code:

    VB.NET-Quellcode

    1. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    2. ' timer2 will draw the shape of the clock and the marks
    3. tick += 6
    4. tick2 += 30
    5. Dim g As Graphics
    6. Dim hoursMarks As New Pen(Color.Black)
    7. hoursMarks.Width = 5
    8. g = Me.CreateGraphics
    9. g.DrawPie(Pens.Black, 249, 149, 380, 380, tick, 360)
    10. g.DrawPie(hoursMarks, 249, 149, 380, 380, tick2, 360)
    11. g.DrawEllipse(Pens.White, 269, 169, 340, 340)
    12. g.FillEllipse(Brushes.White, 269, 169, 340, 340)
    13. If tick > 800 Then
    14. 'drawing the shape is done and the timer will stop
    15. Timer2.Stop()
    16. tick = 270
    17. tick2 = 270
    18. End If
    19. End Sub




    Note: Change the form WindowState property to Maximum to better see the clock working.

    VB-Tag eingefügt. MfG gs93

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „gs93“ ()