473,782 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#) How to keep drawing graphics by GDI

I have some quiestion...

I want to draw line,point,rect angles and etc... on the from
So I code like this..

public update()
{
g = this.CreateGrap hics();
g.FillRectangle (Brushes.White, x1, y1, x2, y2);
}

But the rectangle is removed after window update (minimizer or overrap
by other window)
How can I keep my drawing??

Someone recommand to draw somethins in paint event but I have
question...

My question is... do I need to keep all draw information at some class
or variable to use by paint event???
For example..
If I draw 10 rectangles by using x1,x2, y1,y2, does paint event need
all 10 datas when redraw??

What I want to do is ...
1. A class send position data to B class
2. when B class receive data, B class draw on form by GDI
3. A glass update position data (goto 1)

looping like 1-2-3- 1-2-3- 1-2-3 about 1000 more times

in this case do I also need to draw something at paint event?
and does B class need to keep all data to use at redraw time??

please help me..

Jun 8 '07
11 9308
On Sun, 10 Jun 2007 17:43:15 -0700, <ct*****@gmail. comwrote:
I read all you guys reply (Thanks..)
But I still dont know how to maintain something drawed.
I'm not clear on why not, as it seems to me that the question was answered
correctly and more than once.

That said...
What I'm doing is realtime updating which is updated in a unit of
every 0.5~1 secs and the updating is a lot...
Updating every half second to second is child's play for a modern
computer, even when including a _lot_ of information in the update.
It's possible to keep a lot drawing information in a array, but i
don't know performance.. (Actually I do not want to keep the data..)
If you do not want to keep the data, then why do you want to keep
displaying it?

Something to keep in mind: if it is taking you so long to draw everything
you want from scratch, then it is likely that you are drawing more
information to the screen than any human user will be able to comprehend..

Conversely, if you have a mechanism in mind for "aging" the information
and throwing out old information, then you can apply that to stored data
as well as you can to a cached bitmap (better than, actually).
After update something, I want to remove the information in every class..
So, do that. No one said you had to save ALL of the information you ever
receive. You just have to save the information that will be important the
next time Windows asks you to redraw your form.
Somebody tell me the OS system or Video card remember drawing
information in a cache or somewhere, So I do not need to keep that but
I don't know how to do it...
Somebody tell you? If anyone told you that what you draw once is
automatically saved for you, they were wrong. That's just not part of the
standard Windows screen updating paradigm (nor of most other GUI operating
systems for that matter).
Does any body show me the short sample code.
Please help me.... . ;;;;
Here is some short code that should give you the idea:

private Bitmap _bmpCache;

void UpdatedData()
{
Graphics gfx = Graphics.FromIm age(_bmpCache);

// use gfx Graphics instance to draw whatever you want to draw
}

protected override void OnPaint(object sender, PaintEventArgs e)
{
e.Graphics.Draw Image(_bmpCache , 0, 0);
}

You need to make sure that _bmpCache is initialized to a Bitmap the
correct size for your form (or at least, the size you expect to draw to)..
You will need to clear the bitmap manually any time you think that is
appropriate, because everything you draw will just keep piling up in the
bitmap otherwise.

Hope that helps.

Pete
Jun 11 '07 #11
On Mon, 11 Jun 2007 00:40:34 -0700, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
void UpdatedData()
{
Graphics gfx = Graphics.FromIm age(_bmpCache);

// use gfx Graphics instance to draw whatever you want to draw
}
And yes, I'm playing the "this is just demo code" card. You should, of
course, make sure to dispose the Graphics object once done with it, either
explicitly, or implicitly with a "using" statement.
Jun 11 '07 #12

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

Similar topics

9
2411
by: Steve Long | last post by:
Hello, (total GDI newbie) I'm having trouble drawing just a simple line to display in a picturebox. I just want a straight, dotdash line. I have two methods, one works and one doesn't (it cause an exception to be thrown): This one works but it's not the results I want. private void CreateImage1() {
1
9577
by: Paul Hoad | last post by:
I'm trying to use MeasureString() to determine the length in pixels of a string However to do I need a System.Drawing.Graphics object to do this I need to create a System.Drawing.Graphics object for which there is only two constructors System.Drawing.Graphics.FromHdc
4
12345
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text (centered in the label) on this label. My font on this label is Courier new - hence fixed width character cells.
1
3235
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To get the best performance for the utility class, its members, as well as the System.Drawing.Graphics object, are static:
5
3867
by: Arthur Hsu | last post by:
Hello, I have an ImageButton that refers to an external image. How can I keep that image's aspect ratio when I set the ImageButton's size to 120x120? TIA, Arthur
13
3348
by: Metallicraft | last post by:
I have a vb6 application. On the main form is a picture box with one or two images and several pieces of text displayed in it. These are created on the fly using gdi32 routines that are all in a referenced, custom dll. I call a PrintImage routine in the dll and pass it only the the Picturebox.hdc from the main form. The dll's print routine draws to the hdc and it shows up in the picturebox perfectly. I would like to do a similar thing...
2
2691
by: Peter Proost | last post by:
Hi group, I got the following piece of code which draws a square with stars round it, now I want the stars to rotate round the square, I can do this with the mx.rotate and a timer and an angle, but this rotates the whole drawing of the stars but what I realy want is for the stars to rotate round it's center point, is this possible? I hope I was clear enough in my explanation. Thanks in advance
0
3558
by: Hasim AH | last post by:
Hi .. Just getting interested to learn C# and needs help. I want to write C# application so that the program will execute and draw graphics when the user select the drawing menu from the main menu, SigDraw. Here is the codes:- using System; using System.Drawing; using System.Collections;
2
3106
by: Carl | last post by:
I'm new to C#, and I have only limited programming experience. I've been doing the video tutorials at MS's website, and they're very helpful, but I decided to experiment with GDI+ and have gotten stuck. I'm trying to draw a bitmap on my main form and then to draw a second bitmap, as if it were a sprite (e.g., a "unit" in a wargame), on top of the first. The main form renders fine; I handle the Paint event by creating a temporary Graphics...
0
9643
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
9480
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
10313
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
10147
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...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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
5378
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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.