473,795 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3178
* "Dafü" <an*******@disc ussions.microso ft.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.FromI mage'. 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.n et/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*******@disc ussions.microso ft.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.Drawi ng

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*******@disc ussions.microso ft.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.Drawi ng

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
1616
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 image1 is drawn to the screen
12
2389
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
8
12282
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 Invalidate(Rectangle)) flickers in a nasty way when repainting. This does not happen in the Solitare (PC + WinCe) Versions a well as in a Card game where I have the C++ Source. The use of an empty OnPaintBackground brings no visable results.
3
8999
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 full alpha blending. Basically I'm trying to make a layered window that supports controls. In order to do that I need to redirect painting of the controls to a memory DC (which is then sent to the layered window). All this asuming that I figured out...
2
345
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 you
7
2583
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 stupid or missing the point. I used DrawString( ) as a simple test but I cannot get it to work at all unless I handle my custom controls Paint event.
8
12780
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 to me please? A) protected static extern IntPtr GetWindowDC (IntPtr hWnd );
9
4273
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 Graphics object, which is the same as if I'd need to print it. It'd be easy using Control.DrawToBitmap, but I also need the invisible part of the panel (which is hidden because of scrolling) and DrawToBitmap just takes a screenshot.
3
1549
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 image into PictureBox1 will only work if wire it up to a button, it doesn't actually do anything if...
0
9672
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.