Inherited form issue?

T

TJ

Hi,

Environment: .NET CF 2.0 / VS 2005.

I created a from base class, then child form by using inherited from dialog
box.
So class looks like..

public partial class frmBase : Form {
.....
....
}

this is base class....

public partial class frmChild : frmBase {
...
...

}

This is a child class inherited from frmBase.

It seems to work OK...however, the problem occurs when I add some logic in
onLoad event in the base class..

For example,

In the frmBase class...OnLoad event is overriden..

protected override void OnLoad(EventArgs e)
{
String imageFile = "......\xyz.jpg";
System.Drawing.Image image = new System.Drawing.Bitmap(imageFile );
this.PictureBox.Image = image;
}

The logic is simple...just read image file, then load it onto picture box.
The reason why I decided not to embed this image is that I want to have some
flexibility. ..........as long as the image file name is same, I can use
different image by only changing the image file without recompiling the
solution set.

It seems to run OK. however, it complains in the form designer in VS.NET 2005.

Parameter is not valid.

at System.Drawing.Bitmap..ctor(String filename)
......
at frmBase.OnLoad(EventArgs e) in ....\frmBase.cs:line 24
....

It seems that the form designer won't be able to load that image dynamically
at the form designer level.......Well..I guess it makes sense somehow,
however, in the form designer, is there anyway I can prevent generating from
this error message?
Well..if I could see that image on the form designer, that also would be
great.

Is conditional compiler header only way like #define FORM_DESIGN???

Thanks,
 
S

Simon Hart [MVP]

This is because as you say on the desktop VS is trying to load the bitmap
which it can't probebly find.

You could code something like the following:

protected override void OnLoad(EventArgs e)
{
#if NETCFDESIGNTIME
String imageFile = "......\xyz.jpg";
System.Drawing.Image image = new System.Drawing.Bitmap(imageFile );
this.PictureBox.Image = image;
#ELSE
//EXAMPLE Load a sample image that exists on desktop:
strng imageFile = @"C:\windows\tempimage.bmp";
System.Drawing.Image image = new System.Drawing.Bitmap(imageFile
);
this.PictureBox.Image = image;
#ENDIF
}

Alternatively use the Control.Site.DesignMode property:
http://msdn.microsoft.com/en-us/library/system.componentmodel.isite.designmode(VS.71).aspx

That link above is for VS 2003, search MsDN for v8.0 although I don;t think
there are any changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top