In the project, a chart is used to display the opening degree of a valve and the opening degree of the control valve. I used to use the pie chart in the control bought by any company, but I think it is also troublesome. I just want to draw it by myself.
First, add a TrackBar named "TrackBar1", a label named "L_A_SHANG", a GroupBox named "GB_RIGHT", and then add the processing function when pulling the scroll bar.
PC Control
Dim m_start As Integer
Dim RcDraw As System. Drawing. Rectangle
Private Sub TrackBar1_Scroll (ByVal sender As Object, ByVal e As System. EventArgs) Handles TrackBar1.Scroll
M_start = (100-TrackBar1.Value)
Me. L_A_SHANG.Text = Me. TrackBar1.Value. ToString
GB_RIGHT.Invalidate () redraw GB_RIGHT
End Sub
Processing function when GB_RIGHT is added for repainting
Private Sub GB_RIGHT_Paint (ByVal sender As Object, ByVal e As System. Windows. Forms. PaintEventArgs) Handles GB_RIGHT.Paint
RcDraw. X = TrackBar1.Location. X-40
RcDraw. Y = 20
RcDraw. Height = 100
RcDraw. Width = 20
E. Graphics. DrawRectangle (New Pen (Color. Blue, 5), RcDraw)
Dim I = TrackBar1.Location. X-40
For I = TrackBar1.Location. X-40 To TrackBar1.Location. X-20
E. Graphics. DrawLine (New Pen (Color. Blue, 5), I, m_start + 20, I, 120)
Next
Me. L_A_SHANG.Text = Me. TrackBar1.Value. ToString + "%"
End Sub
At this point, the image changes and the percentage is displayed.