guanzhao

Hi Experts,

Currently I am having problems related to created graphics vanishing from my program form after another program form overlap my graphics. Is there anyway to fix this bug

I have declared Graphics object (Graphics gr;//Declared in public class) in public class so as to call upon the method FillEllipse at another event handler as the input parameters for FillEllipse are updated through the other event handler (not inside the Paint event handler).

However, (gr = groupBox.CreateGraphics(); or gr = e.Graphics; // I do not know which one to use as I want to create the graphics in groupbox.) is declared in the groupbox_Paint event handler.

Can the vanishing graphics' bug be resolved

Hope to hear from you people soon.

Thanks



Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Bring Up My Post





Re: Visual C# Express Edition Vanishing Graphics on program form

JohnWein

There is no vanishing graphics bug. The monitor screen is shared by all applications on the computer. When you use CreateGraphics and draw you modify the contents of the graphics memory on the graphics card which in turn, modifies what appears on the screen. Your modification remains in graphics memory until some other application modifies the same memory. You are notified that you must redraw through the paint event. If you don't redraw then your drawing is lost or vanishes.





Re: Visual C# Express Edition Vanishing Graphics on program form

Chris Dunaway

Check this link and the very first question:

http://www.bobpowell.net/faqmain.htm

Chris





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Hi Experts,

I've tried the program codes, and it worked, but not to my program.

Basically, my program would receive data (x, y coordinates) from an excel file, and according to these data files, plot a graph using the FillEllipse function. As these data from the excel file changes, FillEllipse is to be called whenever there is a change. Up till now, I've only managed to call FillEllipse inside the Paint event of a Panel to paint at the specfic location. However, when a new set of data is retrieved from the excel file, and when FillEllipse is called again, the plotted 'dot' disappears and a new point is plotted. This means instead of getting a graph, I would only have a point on the Panel only.

Can anyone enlighten me on this situation

Thanks





Re: Visual C# Express Edition Vanishing Graphics on program form

JohnWein

Do your drawing on a bitmap and then display the bitmap on the panel.





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Hi John,

What do you mean drawing on a bitmap

F.Y.I: My program has to be constantly drawing on the panel. It cannot be drawn on something else first, then displayed altogether at once onto the screen.

Thanks





Re: Visual C# Express Edition Vanishing Graphics on program form

IsshouFuuraibou

Guanzhao,

One of the abilities of the framework with GDI+ (how you draw controls) is that you can create a graphics object for a bitmap/image and draw to that.

This is the basic psudo-code:
Bitmap b = new Bitmap();
Graphics g = Graphics.FromImage(b);

then you can draw to the bitmap with "g." then finally when you've drawn to the bitmap, you can later draw the bitmap to the control in the paint method. This way you still get current drawing, but you don't lose any previous drawings.
e.graphics.DrawBitmap(b);

The issue is you need to either draw to something that will remember previous draws or you'll need to redraw all of your data. This can become unfeasable for performance to continously redraw a large number of points/lines by iteration. Drawing to the bitmap( or any Image ) in memory saves the drawing and can be painted all at once.





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Hi IsshouFuuraibou,

Sorry for the late reply again.

So how do I display the Bitmap out on the form I am using a groupbox for it's coordinates to put my graphics in. How do I implement this method

Thanks





Re: Visual C# Express Edition Vanishing Graphics on program form

IsshouFuuraibou

In the Paint event for the groupbox, you would just want to draw the bitmap to the form with

private void groupBox1_Paint( object sender, EventArgs e )
{
e.graphics.DrawImage( b );
}


DrawImage Method this works because bitmap is a descendant of Image.





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Hi IsshouFuuraibou,

I have tried using Bitmap b = new Bitmap(). But there was an error which says Bitmap requiring an argument or sort. I still do not quite get how the codes can be implemented into my program.

Till now my program for groupBox1_Paint goes like this:

//Start code

gr = groupBox1.CreateGraphics(); //gr declared in public.

gr.TranslateTransform(0, groupBox1.Height);

gr.ScaleTransform(1, -1);

//End code

That is all I have in the paint event. At another event of the program, I am required to draw the image using gr.FillEllipse() method. This is where I am having trouble storing the image.

Can you help me with this

Thanks a lot





Re: Visual C# Express Edition Vanishing Graphics on program form

JohnWein

This site may help you get started.





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Hi,

I've tried that before. But I cant seem to get the codes work -.-

Thanks





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao


Bring Up My Post





Re: Visual C# Express Edition Vanishing Graphics on program form

guanzhao

Bring Up My Post