By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

graphics, drawing problem

P: n/a
Hi,

When I draw a bitmap on a form, the bitmapdrawing disappears when I move the
form, how is it possible to lock the drawing so it stays visible when you
move or do somethings else....

Thx
Jeroen
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
> When I draw a bitmap on a form, the bitmapdrawing disappears when I move
the
form, how is it possible to lock the drawing so it stays visible when you
move or do somethings else....


Have you tried implementing the Paint() event? Redrawing would be easier
than trying to "lock" the image.
Nov 15 '05 #2

P: n/a
No i didn't, what do you mean by implementing?
A sort of repaint?

"Frecklefoot" <Chris_nospam@nospam_nsageotech.com> schreef in bericht
news:ez**************@TK2MSFTNGP09.phx.gbl...
When I draw a bitmap on a form, the bitmapdrawing disappears when I move

the
form, how is it possible to lock the drawing so it stays visible when you move or do somethings else....


Have you tried implementing the Paint() event? Redrawing would be easier
than trying to "lock" the image.

Nov 15 '05 #3

P: n/a
Jeroen,

The way that windows works is that there is a loop which does nothing
but process messages. One of these messages is a command which indicates
that the window should repaint itself. When this happens, in .NET usually
the OnPaint method of a Control class is called (which is exposed in a Form,
because Form extends Control).

Now, if you call a method to paint a bitmap in a button click, the image
will appear, but the next time the window gets a notification to re-paint
itself, it will dissapear, because there are no instructions to keep the
bitmap painted (you did it once in the button click, and the OnPaint method
or the Paint event handler doesn't have any knowledge of your bitmap).

The paint routine is really a state machine. You should override
OnPaint. In it, you call the base implementation. Then, you check the
state. If a bitmap exists to paint, then paint it, otherwise, do nothing.

Now, in your button click (or wherever you set the bitmap), you would
load the picture, and then store it where the OnPaint method can access it.
Then, you would call the Invalidate method. This will send a message to
your window to repaint itself, at which point, your custom code in OnPaint
will paint the loaded bitmap.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
No i didn't, what do you mean by implementing?
A sort of repaint?

"Frecklefoot" <Chris_nospam@nospam_nsageotech.com> schreef in bericht
news:ez**************@TK2MSFTNGP09.phx.gbl...
When I draw a bitmap on a form, the bitmapdrawing disappears when I
move
the
form, how is it possible to lock the drawing so it stays visible when

you move or do somethings else....


Have you tried implementing the Paint() event? Redrawing would be easier
than trying to "lock" the image.


Nov 15 '05 #4

P: n/a
100
Hi Jeroen,

Set the bitmap as a backgound image.
Control.BackgroundImage. The framework will take care of drawing the bitmap
on the form

HTH
B\rgds
100
Nov 15 '05 #5

P: n/a
Visit the GDI+ FAQ and look at the number 1 most frequently asked question.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

When I draw a bitmap on a form, the bitmapdrawing disappears when I move the form, how is it possible to lock the drawing so it stays visible when you
move or do somethings else....

Thx
Jeroen

Nov 15 '05 #6

P: n/a
Thx!

I put in these code: and the bmp keeps there! I have a few questions about
it, what does the base.OnPaint(e) mean?

private void button1_Click(object sender, System.EventArgs e)

{

button1_clicked=true;

bmp=new Bitmap(@"\\geronimo\im\ImageWeftIllum.bmp");

this.Invalidate();

}

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

if (button1_clicked==true)

g.DrawImage(bmp,10,10);
}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schreef
in bericht news:%2***************@TK2MSFTNGP09.phx.gbl...
Jeroen,

The way that windows works is that there is a loop which does nothing
but process messages. One of these messages is a command which indicates
that the window should repaint itself. When this happens, in .NET usually
the OnPaint method of a Control class is called (which is exposed in a Form, because Form extends Control).

Now, if you call a method to paint a bitmap in a button click, the image will appear, but the next time the window gets a notification to re-paint
itself, it will dissapear, because there are no instructions to keep the
bitmap painted (you did it once in the button click, and the OnPaint method or the Paint event handler doesn't have any knowledge of your bitmap).

The paint routine is really a state machine. You should override
OnPaint. In it, you call the base implementation. Then, you check the
state. If a bitmap exists to paint, then paint it, otherwise, do nothing.

Now, in your button click (or wherever you set the bitmap), you would
load the picture, and then store it where the OnPaint method can access it. Then, you would call the Invalidate method. This will send a message to
your window to repaint itself, at which point, your custom code in OnPaint
will paint the loaded bitmap.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
No i didn't, what do you mean by implementing?
A sort of repaint?

"Frecklefoot" <Chris_nospam@nospam_nsageotech.com> schreef in bericht
news:ez**************@TK2MSFTNGP09.phx.gbl...
> When I draw a bitmap on a form, the bitmapdrawing disappears when I move the
> form, how is it possible to lock the drawing so it stays visible when
you
> move or do somethings else....

Have you tried implementing the Paint() event? Redrawing would be

easier than trying to "lock" the image.



Nov 15 '05 #7

P: n/a
base.OnPaint calls the base class implementation. In this case it does no
drawing but it does raise the Paint event.

Leaving it out may not break your code but it may prevent other people who
use your component from doing custom painting of their own.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
Thx!

I put in these code: and the bmp keeps there! I have a few questions about
it, what does the base.OnPaint(e) mean?

private void button1_Click(object sender, System.EventArgs e)

{

button1_clicked=true;

bmp=new Bitmap(@"\\geronimo\im\ImageWeftIllum.bmp");

this.Invalidate();

}

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

if (button1_clicked==true)

g.DrawImage(bmp,10,10);
}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schreef
in bericht news:%2***************@TK2MSFTNGP09.phx.gbl...
Jeroen,

The way that windows works is that there is a loop which does nothing
but process messages. One of these messages is a command which indicates that the window should repaint itself. When this happens, in .NET usually the OnPaint method of a Control class is called (which is exposed in a

Form,
because Form extends Control).

Now, if you call a method to paint a bitmap in a button click, the

image
will appear, but the next time the window gets a notification to re-paint itself, it will dissapear, because there are no instructions to keep the
bitmap painted (you did it once in the button click, and the OnPaint

method
or the Paint event handler doesn't have any knowledge of your bitmap).

The paint routine is really a state machine. You should override
OnPaint. In it, you call the base implementation. Then, you check the
state. If a bitmap exists to paint, then paint it, otherwise, do nothing.
Now, in your button click (or wherever you set the bitmap), you would load the picture, and then store it where the OnPaint method can access

it.
Then, you would call the Invalidate method. This will send a message to
your window to repaint itself, at which point, your custom code in OnPaint will paint the loaded bitmap.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
No i didn't, what do you mean by implementing?
A sort of repaint?

"Frecklefoot" <Chris_nospam@nospam_nsageotech.com> schreef in bericht
news:ez**************@TK2MSFTNGP09.phx.gbl...
> > When I draw a bitmap on a form, the bitmapdrawing disappears when
I move
> the
> > form, how is it possible to lock the drawing so it stays visible

when you
> > move or do somethings else....
>
> Have you tried implementing the Paint() event? Redrawing would be easier > than trying to "lock" the image.
>
>



Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.