views:

496

answers:

2

Hi,

I am new to windows mobile. I need to set a background image for the form but i can see only the option to set background colour. Also i tried to set background image for tab control there also i didnt see any option to set background image. How can i set the background image.

Thanks,

+1  A: 

Override OnPaint and draw in your own image. Something like this:

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    e.Graphics.DrawImage(myBackGroundBitmap, 0, 0);
}

Of course you need to load that image, and you may want to tile, center or scale it, but the process is really simple.

ctacke
can you please help me with code samples
Timmi
Wouldn't it be better to override OnPaintBackground in this case? (Or am I then mixing up the regular and the compact framework again?)
peSHIr
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Bitmap bmp = new Bitmap("C:\\test.bmp"); e.Graphics.DrawImage(bmp, 0, 0); }I tried the above code but an error saying could not find part of the path is shown in the lineBitmap bmp = new Bitmap("C:\\test.bmp");what could be the error
Timmi
There is no concept of a drive in WIndows CE, so the path you have is invalid.
ctacke
+1  A: 

Another "low-tech" solution is to simply place a picture box control onto your form and use the "send to back" feature within the forms designer to ensure the control is positioned behind any of your other controls.

This approach doesn't need any code to be written and you can configure the image scaling options etc via the Visual Studio property window.

Christopher Fairbairn