Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55346

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Drawing problem - refresh not working Posted by corinarus on 19 Jul 2012 at 1:17 AM
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)

Public Class Form1

    Public lines As New ArrayList


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        DrawLines()
    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))
            'line.Draw()
            lines.Add(line)

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

        Panel1.Invalidate()
        Panel1.Update()


    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
            linie.Draw()
        Next linie
    End Sub
End Class




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.