473,387 Members | 1,844 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,387 software developers and data experts.

Graphics painting VB.NET

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 window all graphs disapear.

How can I maintain the graphics?

I use to draw the graphics lines, boxes of the namespace

System.Drawing

Thanks for the answer
Nov 20 '05 #1
4 3143
* "Dafü" <an*******@discussions.microsoft.com> scripsit:
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 window all graphs disapear.

How can I maintain the graphics?

I use to draw the graphics lines, boxes of the namespace


Create a bitmap with the appropriate size first ('Dim b As New
Bitmap(...)'). Then get a 'Graphics' object for this bitmap using
'Graphics.FromImage'. Use this object to draw onto the bitmap and paint
the bitmap onto the form in the form's 'Paint' event handler.

Maybe you want to subscribe to Bob Powell's "Well Formed":

<http://www.bobpowell.net/August2003.htm>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #2
On Mon, 10 Nov 2003 14:48:38 -0800, "Dafü"
<an*******@discussions.microsoft.com> wrote:
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 window all graphs disapear.

How can I maintain the graphics?

I use to draw the graphics lines, boxes of the namespace

System.Drawing

Thanks for the answer


Actual drawing should take place in the OnPaint event handler of the
object you're painting onto (eg. a Form). When you require complex
drawing, as you seem to indicate, it's best to pre-process as much as
possible somewhere else, so only a very limited amount of calculation
is performed in the OnPaint. A normal place to do this is in the same
place you calculate the resizing of the Form (control, or whatever).

Having said that, you can find the part of the Form that has been
uncovered by another window by looking at the invalidated rectangle.
You can just redraw the contents of that rectangle to preserve the
output. However, sometimes this itself is so complex that the amount
of time it takes to workout what the contents of the invalidated
rectangle should be, that it would actually be quicker to redraw the
whole page.

So, to summarise (and this is for all Windows applications, not just
VB.NET):

1) Perform as much of the calculation as possible in Form_Resize. This
can include complex mathematical computation, scale factors etc.

2) Fonts etc. (and their heights etc.) can be loaded or discovered in
Form_Load, although it is sometimes useful to put this into
Form_Resize instead.
eg. When a font or some text changes, it might be necessary to
calculate the size of the rectangle it takes to draw - a natural place
for this is in a separate function (called from Form_Resize and in the
property handler of the Font in question).

3) Perform all drawing in the Form_Paint method. This will be all the
Graphics.Draw* methods etc. Ideally, you should concentrate on the
implementation here to make it operate as fast as possible. Also, you
should try to avoid things like painting the same point more than
once. On virtually all occasions, you can abandon the handling of clip
rectangles (ie. be lazy) to no noticeable decrease in performance.

4) The code for (1) and (2) can be called by yourself at any time. The
Form_Resize method is called by the framework before the first Paint
event is fired.

Rgds,


Nov 20 '05 #3
"Dafü" <an*******@discussions.microsoft.com> schrieb
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 window all graphs disapear.

How can I maintain the graphics?

I use to draw the graphics lines, boxes of the namespace

System.Drawing

Thanks for the answer


Whenever the OS wants you to paint the window, you should paint it. This can
be done in the control's paint event, or by "overriding" OnPaint.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
This used to be so easy in VB6, with Autoredraw. But now
you are on your own..:-)

Whenever you form is redrawn you have to redraw all
additional stuff you want. Easiest is to use a bitmap as
Herfried pointed out, but some people also put all their
redraw logic in the OnPaint.

Regards,
Anand
VB.NET MVP
http://manand.typepad.com
-----Original Message-----
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 window all graphs disapear.

How can I maintain the graphics?

I use to draw the graphics lines, boxes of the namespace

System.Drawing

Thanks for the answer
.

Nov 20 '05 #5

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

Similar topics

0
by: Pudibund | last post by:
Ok, I've spent nearly a week trying to sort what should be an easy task to accomplish but I'm totally flumoxed! I want to do something pretty simple... 1. display image1 2. wait until...
12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
8
by: Mark Johnson | last post by:
Using: VS 2003 NET C# for Framework and Framework Compact Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on OnMouseMove Problem : The affected drawing Area by Invalidate (or...
3
by: pacemkr | last post by:
Is it possible to force a control to paint to a Graphics object (or Device Context, or a bitmap, anywhere aside from the form) that I provide. I am writing a windows form class that supports...
2
by: Lore Leunoeg | last post by:
Hello What is the difference between: - overriding the OnPaint Method and - using the Form_Paint event to do graphics? Is there a difference and what should I prefer for which aim? Thank...
7
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
9
by: she_prog | last post by:
Dear All, I need to save the content of a panel to a bitmap. The panel can have many child controls which also need to be saved. The problem would be solved if I could have the panel saved to a...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...

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.