Drawing problem - refresh not working - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Drawing problem - refresh not working

corinaruscorinarus Posts: 2Member
Hello, I have a problem concerning drawing on a panel. What I need to do is create a timeline, meaning I draw some vertical and horizontal lines. The problem occurs when I scroll the panel. All the drawing that should be in the scrolled area dissappears. I tried to set the paint event of the panel, but then it just draws the lines chaotically (one vertical line just after the other, not at specified intervals). I have no idea what to try further on.

Here is my code, with just the vertical lines: (drawing is performed on a panel -Panel1)

[code]Public Class Form1

Public lines As New ArrayList

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
End Sub

Private Sub DrawLines()
Dim myVerticalPen As New System.Drawing.Pen(System.Drawing.Color.Black, 3)
Dim myHorizontalPen As New System.Drawing.Pen(System.Drawing.Color.BlueViolet, 10)
Dim formGraphics As System.Drawing.Graphics
Dim dashValues As Single() = {5, 2, 10, 4}
Dim blackPen As New System.Drawing.Pen(System.Drawing.Color.Black, 1)

Dim datesLabelArray(20) As Label 'create an array of labels for the date(horizontal) part of the timeline
Dim CurrD As DateTime = "07/12/2012"
Dim labelPosX As Integer = 100
Dim labelPosY As Integer = 50

Dim line As Line
formGraphics = Panel1.CreateGraphics()
blackPen.DashPattern = dashValues

'display vertical part of timeline (partno labels)
Dim partsLabelArray(15) As Label 'create an array of labels for the part(vertical) part of the timeline

For x = 0 To partsLabelArray.Length - 1 'initialize the array of labels
partsLabelArray(x) = New Label
partsLabelArray(x).Name = "myPartLabel" + x.ToString()
partsLabelArray(x).Text = "mypart" + x.ToString()
partsLabelArray(x).Visible = True 'Initializing the TextBox so that it is not rendered in the browser
partsLabelArray(x).AutoSize = True
partsLabelArray(x).Left = 10
partsLabelArray(x).Top = labelPosY

Panel1.Controls.Add(partsLabelArray(x)) 'Adding the TextBox to the Panel that holds the text boxes.
CurrD = CurrD.AddDays(1)
labelPosY += 30
Next x

CurrD = "07/12/2012"

For x = 0 To datesLabelArray.Length - 1 'initialize the array of labels
datesLabelArray(x) = New Label
datesLabelArray(x).Name = "myDateLabel" + x.ToString()
datesLabelArray(x).Text = CurrD
datesLabelArray(x).Visible = True 'Initializing the TextBox so that it is not rendered in the browser
datesLabelArray(x).AutoSize = True
datesLabelArray(x).Left = labelPosX + 20
datesLabelArray(x).Top = 20

line = New Line(myVerticalPen, formGraphics, New Point(labelPosX + 110, 50), New Point(labelPosX + 110, labelPosY - 50))

Panel1.Controls.Add(datesLabelArray(x)) 'Adding the TextBox to the Panel that holds the text boxes.
CurrD = CurrD.AddDays(1)
labelPosX += 120
Next x


End Sub

Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
For Each linie As Line In lines
Next linie
End Sub
End Class[/code]
Sign In or Register to comment.