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

Home Posts Topics Members FAQ

simple graphics question

Tim
hi

I used to do this

Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics
gfx.FillEllipse blah blah blah

to draw straight onto a form.
but this is frowned up (slow).

so what is the alternative?

does this line make the new graphics in memory?

Dim gfx As System.Drawing.Graphics = CreateGraphics()
gfx.FillEllipse blah blah blah

if so, how do I get the final image onto my form or picturebox?

many thanks

Jun 22 '06 #1
5 1393

"Tim" <Ci************@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
hi

I used to do this

Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics
gfx.FillEllipse blah blah blah

to draw straight onto a form.
but this is frowned up (slow).

so what is the alternative?

does this line make the new graphics in memory?

Dim gfx As System.Drawing.Graphics = CreateGraphics()
gfx.FillEllipse blah blah blah

if so, how do I get the final image onto my form or picturebox?

many thanks


Calling CreateGraphics is pretty slow (or at least slower than using the
existing Graphics object that is already there, in the OnPaint method). So,
override the OnPaint method and use the e.Graphics property :)

Mythran

Jun 22 '06 #2
Tim
interesting.

how do I limit when the onpaint gets called?
say I want to click a button to draw something.

also, I am drawing hundreds of circles on the form. I still think it
would be better to draw them to something in memory, and then dump the
finished thing to the form.

any tips?

Mythran wrote:
"Tim" <Ci************@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
hi

I used to do this

Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics
gfx.FillEllipse blah blah blah

to draw straight onto a form.
but this is frowned up (slow).

so what is the alternative?

does this line make the new graphics in memory?

Dim gfx As System.Drawing.Graphics = CreateGraphics()
gfx.FillEllipse blah blah blah

if so, how do I get the final image onto my form or picturebox?

many thanks


Calling CreateGraphics is pretty slow (or at least slower than using the
existing Graphics object that is already there, in the OnPaint method). So,
override the OnPaint method and use the e.Graphics property :)

Mythran


Jun 22 '06 #3

"Tim" <Ci************@gmail.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
interesting.

how do I limit when the onpaint gets called?
say I want to click a button to draw something.

also, I am drawing hundreds of circles on the form. I still think it
would be better to draw them to something in memory, and then dump the
finished thing to the form.

any tips?


Ok, you really don't want to limit when onpaint gets called:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e) ' This line will cause the form/control to paint
' itself. This also raised the Paint event for
' the form/control.

' Perform you custom paint functions here.
End Sub

What you can do, then, is to create a bitmap object and draw on that object
(of course, you'll need to create your own Graphics class to do this) and
then draw the bitmap onto the form/control using the Graphics object
provided by the OnPaint method. I'm not sure if it is faster though, since
you are creating another instance of the Graphics object on every
call...maybe, instead, you can somehow prevent the actual rendering of the
drawing until you have completed drawing the circles.

You can force the OnPaint method to be called by invalidating the client
area of the form (or just the region you want to repaint) by calling one of
the Invalidate method overloads for the form/control.

I'll check into it and get back to ya via ng.

HTH,
Mythran

Jun 22 '06 #4

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:OL****************@TK2MSFTNGP02.phx.gbl...

"Tim" <Ci************@gmail.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
interesting.

how do I limit when the onpaint gets called?
say I want to click a button to draw something.

also, I am drawing hundreds of circles on the form. I still think it
would be better to draw them to something in memory, and then dump the
finished thing to the form.

any tips?


Ok, you really don't want to limit when onpaint gets called:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e) ' This line will cause the form/control to paint
' itself. This also raised the Paint event for
' the form/control.

' Perform you custom paint functions here.
End Sub

What you can do, then, is to create a bitmap object and draw on that
object (of course, you'll need to create your own Graphics class to do
this) and then draw the bitmap onto the form/control using the Graphics
object provided by the OnPaint method. I'm not sure if it is faster
though, since you are creating another instance of the Graphics object on
every call...maybe, instead, you can somehow prevent the actual rendering
of the drawing until you have completed drawing the circles.

You can force the OnPaint method to be called by invalidating the client
area of the form (or just the region you want to repaint) by calling one
of the Invalidate method overloads for the form/control.

I'll check into it and get back to ya via ng.

HTH,
Mythran


After checking, I believe what you want to do to prevent that actual
rendering of the control is to call SuspendLayout and then ResumeLayout when
you want to render.

HTH,
Mythran

Jun 22 '06 #5
I maintain a bitmap the same size as my control in memory then draw what I
want on the bitmap and when OnPaint is called, copy the bitmap to the
graphics object using bitblt. This can be lightning fast if programmed
correctly.
--
Dennis in Houston
"Tim" wrote:
interesting.

how do I limit when the onpaint gets called?
say I want to click a button to draw something.

also, I am drawing hundreds of circles on the form. I still think it
would be better to draw them to something in memory, and then dump the
finished thing to the form.

any tips?

Mythran wrote:
"Tim" <Ci************@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
hi

I used to do this

Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics
gfx.FillEllipse blah blah blah

to draw straight onto a form.
but this is frowned up (slow).

so what is the alternative?

does this line make the new graphics in memory?

Dim gfx As System.Drawing.Graphics = CreateGraphics()
gfx.FillEllipse blah blah blah

if so, how do I get the final image onto my form or picturebox?

many thanks


Calling CreateGraphics is pretty slow (or at least slower than using the
existing Graphics object that is already there, in the OnPaint method). So,
override the OnPaint method and use the e.Graphics property :)

Mythran


Jun 22 '06 #6

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

Similar topics

2
by: rkeisler | last post by:
hi everyone, i've just started programming in c++. i'm on a PC and am running "wedit" as my compiler. as far as i can tell there are no built-in graphics libraries. could someone please...
13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
1
by: Support | last post by:
Hello: Using asp.net (vb) and I dont want to use active X controls - just server side code. I have uploaded a gif file but I want to resample it to a smaller size like 100 by 100 and save it to a...
5
by: fripper | last post by:
I have a VB 2005 app ... main window has a picture box control (picControl) .... I want to draw a rectangle in that control using GDI+ ... something like: Dim g as graphics = creategraphics|()...
4
by: pcnerd | last post by:
I originally asked this question in the "classic" VB forum. It occured to me after I had sent it that I sent it to the wrong forum. Anyway! Here's the situation. I have VB.NET 2005 Express...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
4
by: Carsten Schmitt | last post by:
Hello, I want to draw a simple pixel (i.e. a red pixel in the center of the screen), which is always in the foreground - even when running a fullscreen application like a DirectX game. I need...
1
by: James Willmott | last post by:
If I have a question, about how to implement a graphics algorithm in C++, but not specifically related to getting the graphics on screen (that I can work out for myself). Would asking for help in...
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
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...
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.