Setze mal 1 PictureBox, 1 TrackBar und 3 Label auf eine Form.
Die X,Y- Werte sind abhängig vom Radius des Kreises und dem Winkel.
Hier hat der Kreis einen Radius von 150 Pixel.
VB.Net will halt den Winkel im Bogenmaß haben.
Dazu muss er umgerechnet werden.
Umrechnung Winkel in Bogenmaß siehe hier.
http://de.wikipedia.org/wiki/Arcus
Angefangen habe ich 1983 mit einem Spectrum 48K und Basic/Assembler
VB.Net erst seit Januar 2006.
Public Class Form1
Dim x As Int32 = 150
Dim y As Int32 = 0
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles TrackBar1.Scroll
x = Int(Math.Round(Math.Cos(TrackBar1.Value * Math.PI / 180) * 150))
Label3.Text = "X = " & x.ToString
y = Int(Math.Round(Math.Sin(TrackBar1.Value * Math.PI / 180) * 150))
Label1.Text = "Y = " & y.ToString
Label2.Text = TrackBar1.Value.ToString & " Grad"
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim w As Int32
Dim p(36) As Point
With e.Graphics
.Clear(Color.Black)
.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
.DrawEllipse(New Pen(Color.YellowGreen, 2), 10, 60, 300, 300)
.DrawLine(Pens.Gray, 160, 50, 160, 370)
.DrawLine(Pens.Gray, 0, 210, 750, 210)
.DrawArc(New Pen(Color.Blue, 2), 10, 60, 300, 300, 0, _
-TrackBar1.Value)
.FillEllipse(Brushes.Yellow, 150 + x, 200 - y, 20, 20)
.DrawLine(Pens.Green, 160, 210 - y, 160 + x, 210 - y)
.DrawLine(Pens.Red, 160 + x, 210 - y, 160 + x, 210)
.DrawLine(Pens.Green, 160, 210, 160 + x, 210)
.DrawLine(Pens.Red, 160, 210, 160, 210 - y)
For w = 0 To 36
p(w) = New Point(350 + w * 10, 210 - Int(Math.Round(Math.Sin(10 _
* w * Math.PI / 180) * 150)))
Next
.DrawCurve(New Pen(Color.YellowGreen, 2), p)
.FillEllipse(Brushes.Yellow, 340 + TrackBar1.Value, 200 - y, 20, 20)
End With
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.Size = New Size(762, 537)
Me.AutoScaleMode = Windows.Forms.AutoScaleMode.None
Me.Text = "X=Cos (Grad * PI / 180) * Radius Y=Sin (Grad * PI /" & _
"180) * Radius"
Me.Font = New Font("Microsoft Sans Sherif", 20, FontStyle.Bold)
PictureBox1.Size = New Size(750, 420)
PictureBox1.Location = New Size(2, 38)
PictureBox1.BackColor = Color.Black
TrackBar1.Size = New Size(744, 42)
TrackBar1.Location = New Size(6, 468)
TrackBar1.Maximum = 360
Label1.Location = New Size(12, 2)
Label1.ForeColor = Color.Red
Label1.Text = "Y = 0"
Label2.Location = New Size(342, 2)
Label2.ForeColor = Color.Blue
Label2.Text = "0 Grad"
Label3.Location = New Size(634, 2)
Label3.ForeColor = Color.Green
Label3.Text = "X = 0"
End Sub
End Class MfG GPM |