473,699 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple graphics question

Tim
hi

I used to do this

Dim gfx As System.Drawing. Graphics = pic1.CreateGrap hics
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 1414

"Tim" <Ci************ @gmail.com> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.com...
hi

I used to do this

Dim gfx As System.Drawing. Graphics = pic1.CreateGrap hics
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******** *************@i 40g2000cwc.goog legroups.com...
hi

I used to do this

Dim gfx As System.Drawing. Graphics = pic1.CreateGrap hics
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.goo glegroups.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********@hot mail.comREMOVET RAIL> wrote in message
news:OL******** ********@TK2MSF TNGP02.phx.gbl. ..

"Tim" <Ci************ @gmail.com> wrote in message
news:11******** **************@ b68g2000cwa.goo glegroups.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******** *************@i 40g2000cwc.goog legroups.com...
hi

I used to do this

Dim gfx As System.Drawing. Graphics = pic1.CreateGrap hics
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
1222
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 point me in the direction of an easy way to do graphics. i need to know where these new libraries go, how to call them, etc. i just want to draw 2D plots (preferably with a .ps or ..pdf output).
13
2260
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
1323
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 file - simple ? right ? Upload -> Original.gif resample save as ->resampled.gif
5
1579
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|() Dim r as Rectangle Dim b as new system.drawing.solidbrush(system.drawing.color.red) r.x = 100 r.y = 100
4
1430
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 Edition. I have a 19" LCD monitor with the resolution set at 1280 by 1024. I want to create a graphics program, say, displaying fractals that will run with the form maximized. Are the XY coordinates on the form independent of the size & resolution of...
6
3241
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 (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
15
1838
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
3108
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 this as an easy entry for programming later a HUD, which shows several informations, like date, time, company logo, etc. Any help or just a simple code example would be appreciated.
1
1475
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 the implemention ( asking things like whether I should use std::vector vs std::list for example ) be off topic here? Thanks, jw.
0
8685
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
9171
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
9032
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
6532
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
5869
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.