Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:53:32+00:00 2026-05-29T22:53:32+00:00

I have the interesting task of doing some graphs using VB.NET. So far, everything

  • 0

I have the interesting task of doing some graphs using VB.NET. So far, everything that I´ve been reading about GDI+ and e.graphics whatever is really weird. All I want to do is

1) Calculate some coordinates clicking button 1

2) Click button 2 to draw a line with the numbers from button 1

3) Click button 1 to get new coordinates

4) click button 2 to draw the previous line AND the new line.

5) click button 3 to clear the graph.

So I decided to draw everthing on top of a Panel, called panel1. I have a routine that draws on screen called drawlines,

Private Sub drawlines(ByVal g As Graphics, ByVal c As Color)
  Dim p As New Pen(c, 1)
  g.DrawLine(p, xStart, yStart, xEnd, yEnd)
  p.Dispose()
End Sub

and the other routines:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  'AddHandler Panel1.Paint, AddressOf DrawLine
  GraphicsHandler = Panel1.CreateGraphics
End Sub

Private Sub drawlines(ByVal g As Graphics, ByVal c As Color)
  Dim p As New Pen(c, 1)
  g.DrawLine(p, xStart, yStart, xEnd, yEnd)
  p.Dispose()
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  'GraphicsHandler = Panel1.CreateGraphics
  GraphicsHandler.DrawLine(myPen, 10, 10, 200, 100)
End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
  xStart = CInt(Math.Ceiling(Rnd() * 200))
  yStart = CInt(Math.Ceiling(Rnd() * 100))
  xEnd = CInt(Math.Ceiling(Rnd() * 200))
  yEnd = CInt(Math.Ceiling(Rnd() * 100))
  Me.Panel1.Invalidate()
End Sub

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Panel1.Paint
  drawlines(e.Graphics, Color.Blue)
End Sub

Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
  GraphicsHandler.Clear(Color.White)
End Sub

So far, only using the GraphicsHandler thing is working, but everytime I try to minimize the window or draw a new line, the previous lines are erased. Can some kind soul explain to me proper way to do the simple 1-5 above? For example, how can I call drawlines()from the button?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:53:39+00:00Added an answer on May 29, 2026 at 10:53 pm

    .NET implements a completely new graphics manipulation model with WinForms and GDI+. Your old VB6 skills will not serve you well in this brave new world.

    So start by ditching the GraphicsHandler. ALL your painting should be done via the Panel’s Paint event.

    You should store each line in an array or List(Of Point) at the form level. Then each time the Paint event is called you draw all your lines again. .NET controls DO NOT REMEMBER their graphical state from one Paint event to the next, unlike VB6 controls.

    If you need to force a redraw at the end of your button Click event you would call your Panel.Invalidate()

    PSEUDOCODE:

    Private myCoordinates As List(Of Point) = New List(Of Point)
    
    Sub Button_click(sender, e)
      '' Store new coordinate
      myCoordinates.Add(New Point(x, y))
      myCoordinates.Add(New Point(x, y))
      myPanel.Invalidate()
    End Sub
    
    
    Sub Panel_Paint(sender, e) Handles myPanel.Paint
      For tIndex As Int32 = 0 To myCoordinates.Count - 1 Step 2
        e.graphics.DrawLine(myCoordinate(tIndex), myCoordinates(tIndex+1))
      Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very interesting task that I need help with. The description is
I have an interesting situation where I need to deploy an ASP.NET MVC app
I have one interesting problem. I must parse mail body (regular expression), get some
I have some interesting problem for an hour.. In my flex project, all width
I have an interesting SQL problem that I need help with. Here is the
I have an interesting problem. The basis of the problem is that my last
I have been doing a phonegap app for android but am stuck on the
In my C# project, I have been dealt with the task of parsing an
I have quite an interesting task at work - I need to find out
I have an interesting task: to write a program which captures input from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.