Meine Picturebox1 hat eine Größe von 1244 x 696
Height = PictureBox1.Size.Height
Witdh = PictureBox1.Size.Width
(Mit oder ohne .Size) liefert für Breite und Höhe aber immer 1980 x 1024 also die Größe der Form1.
Habe zahlreiche Autosize,Zoom,Stretch Varianten ausprobiert und komme einfach nicht dahinter.
Ich möchte die Grafikbox für ein X/Y Koordinatensystem nutzen um Kurvenverläufe anzuzeigen.
Dabei habe ich einen Skalierungsfaktor für Breite und Höhe, aber fast die Hälfte aller Linien landet rechts neben der Picturebox im Nirwana da die verwendete Breite und Höhe ja nicht stimmen.
Hier das Meisterwerk.
Height = PictureBox1.Size.Height
Witdh = PictureBox1.Size.Width
(Mit oder ohne .Size) liefert für Breite und Höhe aber immer 1980 x 1024 also die Größe der Form1.
Habe zahlreiche Autosize,Zoom,Stretch Varianten ausprobiert und komme einfach nicht dahinter.
Ich möchte die Grafikbox für ein X/Y Koordinatensystem nutzen um Kurvenverläufe anzuzeigen.
Dabei habe ich einen Skalierungsfaktor für Breite und Höhe, aber fast die Hälfte aller Linien landet rechts neben der Picturebox im Nirwana da die verwendete Breite und Höhe ja nicht stimmen.
Hier das Meisterwerk.
VB.NET-Quellcode
- Private Sub PictureBox1_Paint(yUpper As Integer, yLower As Integer, median As Integer)
- Dim e As System.Drawing.Graphics
- e = PictureBox1.CreateGraphics
- Dim yzero As Integer = Val(PictureBox1.Size.Height / 2)
- Dim ymax As Integer = Val(PictureBox1.Size.Height)
- Dim xmax As Integer = Val(PictureBox1.Size.Width)
- Dim x As Integer = 0
- Dim y As Integer = 0
- Dim Height = PictureBox1.Size.Height
- Dim Witdh = PictureBox1.Size.Width
- Dim counter As Integer = Threshold ' Threshold added
- Dim yFactor = (Height * YScale) / (yUpper - yLower)
- Dim xStepping As Integer = Witdh / 10
- Dim yStepping As Integer = Height / 20
- Do Until counter + Threshold = RawDataArray.GetUpperBound(0) '
- x = counter * Width / NumberofSamples - Threshold '
- y = Convert_Value_to_Coordinates(y, yFactor, counter, ymax, yStepping)
- e.DrawLine(pen6, xOld, yOld, x, y) ' Kurvenpunkt
- counter += 1
- xOld = x
- yOld = y
- Loop
- ' Y-50% Line
- e.DrawLine(pen5, 0, yzero, xmax, yzero) ' Null Linie
- ' Draw X-Grid
- For i = 0 To Width Step xStepping
- RichTextBox1.Text = RichTextBox1.Text & "0-" & i & "x" & Height & "-" & i & " " & vbCrLf
- e.DrawLine(pen8, i, 0, i, Height)
- Next
- ' Draw Y Grid
- For i = 0 To Height Step yStepping
- e.DrawLine(pen8, 0, i, Witdh, i)
- Next
- ' Draw X indexer
- For i = 0 To Width Step xStepping
- e.DrawLine(pen3, i, 0, i, 20)
- Next
- ' Draw Y indexer
- For i = 0 To Height Step yStepping
- e.DrawLine(pen3, 0, i, 20, i)
- Next
- ' Draw xTime
- Dim x1 = CSng(Witdh / 2 - 105)
- Dim x2 = xStepping * 5
- e.DrawLine(pen4, x1 - 15, 15, x2, 15)
- DrawRectangle(e, x1)
- e.DrawString("t:" & Xtime / 10 & "mS", Font1, Brush3, x1 + 10, 5)
- ' Draw Median Line
- Dim YMedian As Integer = yUpper - (median / yFactor)
- YMedian = ymax - YMedian / yFactor
- YMedian = YMedian * YScale
- Dim YSize As Integer = Width * yFactor
- YMedian = Convert_Value_to_Coordinates(y, yFactor, counter, ymax, yStepping)
- e.DrawLine(pen4, 0, YMedian, YSize, YMedian)
- e.FillRectangle(Brush2, Witdh - 80, YMedian - 10, 80, 20)
- Witdh = Val(PictureBox1.Width)
- RichTextBox1.Text = RichTextBox1.Text & Width
- e.DrawString("M:" & median & "mV", Font1, Brush1, YSize, YMedian - 10)
- End Sub
- Function Convert_Value_to_Coordinates(yConv As Integer, yFactor As Integer, index As Integer, ymaxConv As Integer, ysteppingConv As Integer)
- yConv = yUpper * yFactor - RawDataArray(index) * yFactor ' Umrechnung Wert in Koordianten Step I
- yConv = ymaxConv - yConv ' Umrechnung Wert in Koordianten Step II Spiegeln
- yConv = yConv - ysteppingConv ' Umrechnung Wert in Koordianten Step II Y-zentrieren
- Return yConv
- End Function
- Private Sub DrawRectangle(e As Graphics, x1 As Integer)
- e.FillRectangle(Brush2, x1 + 10, 5, 70, 20)
- End Sub