473,608 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3529
> 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?

"Frecklefoo t" <Chris_nospam@n ospam_nsageotec h.com> schreef in bericht
news:ez******** ******@TK2MSFTN GP09.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.co m

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

"Frecklefoo t" <Chris_nospam@n ospam_nsageotec h.com> schreef in bericht
news:ez******** ******@TK2MSFTN GP09.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.Backgro undImage. 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******** ********@tk2msf tngp13.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(o bject sender, System.EventArg s e)

{

button1_clicked =true;

bmp=new Bitmap(@"\\gero nimo\im\ImageWe ftIllum.bmp");

this.Invalidate ();

}

protected override void OnPaint(PaintEv entArgs e)

{

base.OnPaint (e);

if (button1_clicke d==true)

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

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> schreef
in bericht news:%2******** *******@TK2MSFT NGP09.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.co m

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

"Frecklefoo t" <Chris_nospam@n ospam_nsageotec h.com> schreef in bericht
news:ez******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.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(o bject sender, System.EventArg s e)

{

button1_clicked =true;

bmp=new Bitmap(@"\\gero nimo\im\ImageWe ftIllum.bmp");

this.Invalidate ();

}

protected override void OnPaint(PaintEv entArgs e)

{

base.OnPaint (e);

if (button1_clicke d==true)

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

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> schreef
in bericht news:%2******** *******@TK2MSFT NGP09.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.co m

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

"Frecklefoo t" <Chris_nospam@n ospam_nsageotec h.com> schreef in bericht
news:ez******** ******@TK2MSFTN GP09.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
2366
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
3
4827
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 I make a button with the same, after the click it paints it, why the problem, i can't get out of it.........
8
12266
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 Invalidate(Rectangle)) flickers in a nasty way when repainting. This does not happen in the Solitare (PC + WinCe) Versions a well as in a Card game where I have the C++ Source. The use of an empty OnPaintBackground brings no visable results.
1
9569
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
1
3221
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:
8
3306
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 froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
15
1829
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
3547
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;
8
12759
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 to me please? A) protected static extern IntPtr GetWindowDC (IntPtr hWnd );
3
1534
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 reasons for that, which I won't go into. Anyway, there has always been one tiny bug that has annoyed me - the code that draws the initial graphic image into PictureBox1 will only work if wire it up to a button, it doesn't actually do anything if...
0
8470
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
8142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6813
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...
0
5475
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
3959
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
4022
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2472
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
1
1580
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1327
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.