V
Vergassivellaunus
Guest
I'm adding dinamically labels in a predetermined poisition, related to some chart graph.
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim x, y As Single
Dim N, inizio_unit, fine_unit, interv_unit As Integer
Dim posiz As PointF
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Controls.Remove(num_unit(1))
End Sub
Dim num_unit(256) As Control
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
N = NumericUpDown1.Value
Chart1.Invalidate()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Chart1.ChartAreas(0).AxisX.Maximum = 1000
Chart1.ChartAreas(0).AxisX.Minimum = -1000
Chart1.ChartAreas(0).AxisY.Maximum = 1000
Chart1.ChartAreas(0).AxisY.Minimum = 0
End Sub
Private Sub Chart1_PostPaint(sender As Object, e As ChartPaintEventArgs) Handles Chart1.PostPaint
x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Minimum))
y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
posiz = New PointF(x, y)
posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
inizio_unit = posiz.X
x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Maximum))
y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
posiz = New PointF(x, y)
posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
fine_unit = posiz.X
interv_unit = (fine_unit - inizio_unit) / (N + 1)
For i = 1 To N
Dim a As New Label
num_unit(i) = a
num_unit(i).Text = i
num_unit(i).Top = 10
num_unit(i).Left = Chart1.Left + i * interv_unit
num_unit(i).ForeColor = Color.Black
num_unit(i).Visible = True
num_unit(i).Font = New Font("Arial", 7, FontStyle.Bold)
num_unit(i).Size = New Size(20, 20)
Me.Controls.Add(num_unit(i))
Next i
End Sub
End Class
When i click on numeric control, labels are correctely added, but the old ones should be deleted.
I tryed with the button command:
Me.Controls.Remove(num_unit(1))
for example, but nthing happens.
Thanks, Enzo
Continue reading...
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Dim x, y As Single
Dim N, inizio_unit, fine_unit, interv_unit As Integer
Dim posiz As PointF
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Controls.Remove(num_unit(1))
End Sub
Dim num_unit(256) As Control
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
N = NumericUpDown1.Value
Chart1.Invalidate()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Chart1.ChartAreas(0).AxisX.Maximum = 1000
Chart1.ChartAreas(0).AxisX.Minimum = -1000
Chart1.ChartAreas(0).AxisY.Maximum = 1000
Chart1.ChartAreas(0).AxisY.Minimum = 0
End Sub
Private Sub Chart1_PostPaint(sender As Object, e As ChartPaintEventArgs) Handles Chart1.PostPaint
x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Minimum))
y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
posiz = New PointF(x, y)
posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
inizio_unit = posiz.X
x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Maximum))
y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
posiz = New PointF(x, y)
posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
fine_unit = posiz.X
interv_unit = (fine_unit - inizio_unit) / (N + 1)
For i = 1 To N
Dim a As New Label
num_unit(i) = a
num_unit(i).Text = i
num_unit(i).Top = 10
num_unit(i).Left = Chart1.Left + i * interv_unit
num_unit(i).ForeColor = Color.Black
num_unit(i).Visible = True
num_unit(i).Font = New Font("Arial", 7, FontStyle.Bold)
num_unit(i).Size = New Size(20, 20)
Me.Controls.Add(num_unit(i))
Next i
End Sub
End Class
When i click on numeric control, labels are correctely added, but the old ones should be deleted.
I tryed with the button command:
Me.Controls.Remove(num_unit(1))
for example, but nthing happens.
Thanks, Enzo
Continue reading...