473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

graphics, drawing problem

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
7 3513
> 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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
3
by: Jeroen Ceuppens | last post by:
Hi, When i do this in my programma, in the contstructor of the form: g.DrawImage(i,new Rectangle(0,0,i.Width,i.Height),0,0,i.Width,i.Height,GraphicsUnit.Pixel); it doens't paint it ;( but if...
8
by: Mark Johnson | last post by:
Using: VS 2003 NET C# for Framework and Framework Compact Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on OnMouseMove Problem : The affected drawing Area by Invalidate (or...
1
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...
1
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...
8
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim...
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
0
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...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
3
by: Peter Webb | last post by:
When I started my current extremely graphics intensive project, I ignored advice in this ng to use the Paint method, and used the alternate CreateGraphics approach. I thought there were some good...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
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...

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.