Graphics Redraw Problem

  • Thread starter Thread starter Bob Steuernagel
  • Start date Start date
B

Bob Steuernagel

This code is for a simple drawing program that lets the user draw lines,
rectangles, and circles in different colors. When the menu is dropped down
to change objects, it erases anything drawn underneath the menu drop-down
area. What is wrong?

Imports System.Drawing

Public Class Form1
Inherits System.Windows.Forms.Form


Dim drawchoice As Integer

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
drawchoice = 3
Me.ActiveForm.Show()

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Dim mygc As Graphics = Graphics.FromHwnd(Me.Handle)
Dim mycirPen As New Pen(Color.Red, 4)
Dim myrecPen As New Pen(Color.Green, 3)
Dim mylinePen As New Pen(Color.Blue, 5)
Select Case drawchoice
Case 1
mygc.DrawEllipse(mycirPen, e.X, e.Y, 100, 100)
Case 2
mygc.DrawRectangle(myrecPen, e.X, e.Y, 50, 50)
Case 3
mygc.DrawLine(mylinePen, e.X, e.Y, e.X + 50, e.Y + 50)
End Select
End If
End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem3.Click
drawchoice = 1
Me.ActiveForm.Show()
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click
drawchoice = 2
Me.ActiveForm.Show()
End Sub

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem5.Click
Me.Close()
End
End Sub
 
Bob Steuernagel said:
This code is for a simple drawing program that lets the user draw
lines, rectangles, and circles in different colors. When the menu is
dropped down to change objects, it erases anything drawn underneath
the menu drop-down area. What is wrong?

Probably you don't repaint when Windows wants you to.

http://msdn.microsoft.com/library/en-us/cpguide/html/_gdiplus_drawing_a_line_usecsharp.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
use Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)


or
Private Sub frmLoad_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
 
Back
Top