PC Review


Reply
Thread Tools Rate Thread

background image in a form

 
 
Eka Gautama
Guest
Posts: n/a
 
      25th Sep 2003
Hi there,

I have couple questions:
- how can i put a background image in a form
- how can i set a trasparent bg color a label or button..

Thanks for help..



 
Reply With Quote
 
 
 
 
PeterB
Guest
Posts: n/a
 
      25th Sep 2003
You can overload the paint event:

instantiate a Bitmap called backgroundImage and set it in the constructor
then use this code:

protected override void OnPaintBackground(PaintEventArgs e)

{

// use image for background

e.Graphics.DrawImage(backgroundImage, 0, 0);

}

"Eka Gautama" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi there,
>
> I have couple questions:
> - how can i put a background image in a form
> - how can i set a trasparent bg color a label or button..
>
> Thanks for help..
>
>
>



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      25th Sep 2003
To achieve the first point you can override the OnPaint method of the Form
and draw an image to the form. e.g.
[C#]
protected override void OnPaint(PaintEventArgs e)

{

//paint the splash screen bitmap

Graphics g = e.Graphics;

g.DrawImage(new
Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResource
Stream("background.bmp")),0, 0);

base.OnPaint (e);

}



[VB]

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

Graphics g = e.Graphics

g.DrawImage(New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResource
Stream("background.bmp")),0, 0)

MyBase.OnPaint(e)

End Sub



Note here I have loaded a bitmap from an embedded resource too. You could
use the alternate constructor for the Bitmap object which takes a filepath
to a valid image file.

Peter


--
Peter Foot
Windows Embedded MVP

www.inthehand.com | www.opennetcf.org

"Eka Gautama" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi there,
>
> I have couple questions:
> - how can i put a background image in a form
> - how can i set a trasparent bg color a label or button..
>
> Thanks for help..
>
>
>



 
Reply With Quote
 
PeterB
Guest
Posts: n/a
 
      25th Sep 2003
Why is the base.OnPaint(e) method called?


"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> To achieve the first point you can override the OnPaint method of the Form
> and draw an image to the form. e.g.
> [C#]
> protected override void OnPaint(PaintEventArgs e)
>
> {
>
> //paint the splash screen bitmap
>
> Graphics g = e.Graphics;
>
> g.DrawImage(new
>

Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResource
> Stream("background.bmp")),0, 0);
>
> base.OnPaint (e);
>
> }
>
>
>
> [VB]
>
> Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
>
> Graphics g = e.Graphics
>
> g.DrawImage(New
>

Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResource
> Stream("background.bmp")),0, 0)
>
> MyBase.OnPaint(e)
>
> End Sub
>
>
>
> Note here I have loaded a bitmap from an embedded resource too. You could
> use the alternate constructor for the Bitmap object which takes a filepath
> to a valid image file.
>
> Peter
>
>
> --
> Peter Foot
> Windows Embedded MVP
>
> www.inthehand.com | www.opennetcf.org
>
> "Eka Gautama" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi there,
> >
> > I have couple questions:
> > - how can i put a background image in a form
> > - how can i set a trasparent bg color a label or button..
> >
> > Thanks for help..
> >
> >
> >

>
>



 
Reply With Quote
 
Floris Briolas
Guest
Posts: n/a
 
      25th Sep 2003
PeterB

just leave it out and you'll see...

just imagine that your base class draws a line over the screen, if you
override the paint event and do not call it, it means that the code of the
parent class is not executed, thus resulting into wanted or unwanted
features..

regards Floris

[cut]
why should i call base.
[/cut]


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Background image in Mdi form Miguel Pires Microsoft C# .NET 0 24th Feb 2007 09:20 PM
image as form background Carlos Microsoft ASP .NET 3 15th Apr 2005 03:53 PM
Cannot set form background image =?Utf-8?B?c2thbmpv?= Microsoft Dot NET Framework Forms 3 5th Apr 2005 01:57 AM
Background Image for Web Form =?Utf-8?B?UkNBTQ==?= Microsoft ASP .NET 2 1st Jun 2004 10:35 PM
MDI Form Background Image Ivan Weiss Microsoft VB .NET 2 14th Dec 2003 11:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:51 AM.