473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Graphics Redraw Problem

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
Nov 20 '05 #1
3 2747
"Bob Steuernagel" <st*********@sbcglobal.net> schrieb
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..._usecsharp.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
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

Bob Steuernagel wrote:
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


Nov 20 '05 #3
did u received my email today (friday 11th)?. i had firewall on it
regards

Bob Steuernagel wrote:
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


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dafü | last post by:
Hello! I have an application that paint graphics in VB.NET. Each graphic is painted after a long calculation process. My problem is when another windows pass over my graphics or I resize the...
2
by: Christian Soltenborn | last post by:
Hi guys, I have a question to VB .NET: I add a Graphics object to a panel and use a bunch of DrawLine methods etc (it's really nice and convenient). But: As soon as I send my form (which...
4
by: John Baker | last post by:
I am using a Graphics object to draw on a form. If I pop up a message box, or if say the user minimizes and then restores the form, my graphics are erased (just where the box was in the former...
4
by: Rohan | last post by:
Hi There, If I switch from the Form i have drwan my graphics like Rectangle to some other Window and come back to my graphic window the drawing is disappeared. How should I go abt it? Can if u...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Email Question: When I send an email (basically a sms to a phone) from ms outlook it works fine. When I try to send it pragmatically I get an error stating that it can’t relay for <the email...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have a borderless form that has a transparent background. I only wanted the color that I painted the background with to be transparent and not the controls on the form or the box I draw in the...
11
by: cty0000 | last post by:
I have some quiestion... I want to draw line,point,rectangles and etc... on the from So I code like this.. public update() { g = this.CreateGraphics(); g.FillRectangle(Brushes.White, x1,...
11
by: Slickuser | last post by:
I have this function that will fill the ellipse every 10 seconds with specific x,y,w,h. Now I want do the the reverse, to clear the ellipse with given x,y using Timer at every 30s. Or I have...
2
by: JMecc0 | last post by:
I am drawing simple graphics on a custom control which has a static background image. When I try to rapidly (maybe 50 times per second) redraw the graphics the computer can't keep up. There is no...
4
by: AWW | last post by:
XP VB 2005 drawing line graphics in a PictureBox - from a simple minded former FORTRAN programmer. The help examples have the graphics drawing code (lines & rectangles) in the PictureBox paint...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.