473,569 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Advice needed for drawing program

Hi all,

I'm adding basic drawing capability to an application that I am writing, and
I have been having problems with making the graphics output persist when the
application is re-sized,covered etc.

This is the solution I have come up with, but it seems a bit convoluted.
Before I get too far into the development of the program, could someone cast
an eye over my code and tell me if I have approached it in the correct way,
or suggest a better solution.

Many thanks,

Martin Horn. (See below for my code)

Imports System.Windows. Forms

Public Class ComplexInscript ionDesignerForm
Private Drawing As Boolean = False
Private OldX As Integer = 0
Private OldY As Integer = 0
Private PaintObject As Object
Private CanvasBM As System.Drawing. Bitmap
Private Canvas As Graphics

Private Sub PicCanvas_Mouse Down(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles PicCanvas.Mouse Down

Drawing = True
OldX = e.X
OldY = e.Y
End Sub

Private Sub PicCanvas_Mouse Move(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles PicCanvas.Mouse Move

If Drawing Then
Canvas.DrawLine (Pens.Black, OldX, OldY, e.X, e.Y)
OldX = e.X
OldY = e.Y
PicCanvas.Inval idate()
End If
End Sub

Private Sub PicCanvas_Mouse Up(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles PicCanvas.Mouse Up

Drawing = False
End Sub

Private Sub PicCanvas_Paint (ByVal sender As Object, _
ByVal e As System.Windows. Forms.PaintEven tArgs) _
Handles PicCanvas.Paint

e.Graphics.Draw ImageUnscaled(C anvasBM, 0, 0)
End Sub

Private Sub ComplexInscript ionDesignerForm _Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load

CanvasBM = New System.Drawing. Bitmap( _
PicCanvas.Clien tSize.Width, _
PicCanvas.Clien tSize.Height)

Canvas = Graphics.FromIm age(CanvasBM)
End Sub
End Class
Dec 7 '05 #1
2 1424
"Martin Horn" <mv****@theinte rnet.com> schrieb
I'm adding basic drawing capability to an application that I am
writing, and I have been having problems with making the graphics
output persist when the application is re-sized,covered etc.

This is the solution I have come up with, but it seems a bit
convoluted. Before I get too far into the development of the
program, could someone cast an eye over my code and tell me if I
have approached it in the correct way, or suggest a better solution.


The approach is really good, IMO. I guess the line shouldn't be drawn before
the mouse button is released. Therefore I'd store the line coordinates
(start and end) in variables and paint the line in PicCanvas_Paint (if
drawing=true) additionally to CanvasBM. When the button is released, the
line can be drawn persistently on the bitmap. Thus, I'd write a sub drawing
the line that can be called in mouse-up as well as in piccanvas_paint .

Armin

Dec 7 '05 #2
Hi Armin,

thanks for the feedback and tips. It's the first time I've tried something
like this with VB.Net and it's reassuring to know that I'm starting off in
the right direction.

Kind regards,

Martin Horn.

"Armin Zingler" <az*******@free net.de> wrote in message
news:u%******** **********@tk2m sftngp13.phx.gb l...
"Martin Horn" <mv****@theinte rnet.com> schrieb
I'm adding basic drawing capability to an application that I am
writing, and I have been having problems with making the graphics
output persist when the application is re-sized,covered etc.

This is the solution I have come up with, but it seems a bit
convoluted. Before I get too far into the development of the
program, could someone cast an eye over my code and tell me if I
have approached it in the correct way, or suggest a better solution.


The approach is really good, IMO. I guess the line shouldn't be drawn
before the mouse button is released. Therefore I'd store the line
coordinates (start and end) in variables and paint the line in
PicCanvas_Paint (if drawing=true) additionally to CanvasBM. When the
button is released, the line can be drawn persistently on the bitmap.
Thus, I'd write a sub drawing the line that can be called in mouse-up as
well as in piccanvas_paint .

Armin

Dec 7 '05 #3

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

Similar topics

11
2871
by: dw85745 | last post by:
PROBLEMS I Haven't solved: 1. Timing issue between real-time server #1 and my drawing tools. Will moving the tools (currently within module) to an ActiveX (exe or DLL) solve the problem or will the calls to the ActiveX in the mouse move event still result in a conflict???? Background
9
3180
by: Rick Muller | last post by:
I have a problem that I would like to get some advice on from other Pythonistas. I currently manage a (soon to be) open source project for displaying molecular graphics for a variety of different programs. To do this I need to draw pictures of the molecules, typically using OpenGL, and do some basic control, using some widget set. The code...
0
279
by: Mark Stokes | last post by:
Hi there, I wanted a bit of advice on a program (a prototype) that I am trying to write that uses threads. I will outline what I am attempting to do, and if anyone has any advice on the way I am trying to work I would be most grateful. I am writing a windows forms application. This application defines a class, lets call this myObject. ...
1
9344
by: John | last post by:
I'm trying to use the DrawText() method to draw some very long string text on the Panel with AutoScroll enabled. However, for some unknown reasons, I could not trigger the ScrollBar to show up. Here is the simplicied section of drawing code: private void panel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {...
2
3448
by: James dean | last post by:
I am using Graphics path in my application and i have located the slow areas in my rogram and it seems that the graphics path consistently is slow when doing any operation like adding another graphics path, adding text etc......and also drawing the Graphics path onto the drawing surface using the Graphics class is also slow. Am i doing...
3
1029
by: Damir | last post by:
Hello, I'm asking for help from experienced developers. I was a given a task to make a simple graphic program with following demands : The program must have options to work with 2D and 3D graphic. In 2D mode, it must provide user with ability to draw the line,polyline, some basic poligons, circle and elipse. The user must have the option...
1
9606
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
232
13119
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an...
3
1532
by: Peter Webb | last post by:
When I started my current extremely graphics intensive project, I ignored advice in this ng to use the Paint method, and used the alternate CreateGraphics approach. I thought there were some good reasons for that, which I won't go into. Anyway, there has always been one tiny bug that has annoyed me - the code that draws the initial graphic...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.