Visual Inheritance

S

Sebastian Lampka

Hi,

I would like to put on all my Forms a BackgroundImage. Because it is the
same one I want to
use Visual Inheritance. I am not sure why I have to create a DLL-Library for
my base Form in VS2005,
but this is what I did.

So somewhere in my base form I want to load the image, which should be a
relative path from Application.StartupPath.
Since I find myself in a DLL-Library I have no access to
Application.StartupPath.
My next thought was okay then I make my base class abstract (mustinherit)
and force the derived class to set the path
with a mustoverride method. Unfortunately I cannot set this class to
mustinherit, because the Designer has problems
to create the form.

Can somebody tell me what is the best way would be to solve this.

Thanks,

Sebastian Lampka
 
J

Jeffrey Tan[MSFT]

Hi Sebastian,

Thanks for your post.

First, if you only want to create a base form for all the forms in your
project, there is no need to create a separate Base form library as dll. We
can just add a BaseForm in the current project, then all the other forms in
the project can inherit from this baseform. Because currently, there is
only one project and only 1 assembly will generate, so we can just use
relatvie path in the BaseForm to get the background image. The image should
be placed in the same directory as the assembly.

If you want to reuse this BaseForm in several projects, a dll library is a
good choice. However, we still can live with the relative path without
additional work. This is because when compiling the application project,
VS.net IDE will copy all the referenced private assemblies to the
application exe bin directory, so your baseform dll will be copied to the
Exe directory either. So once we placed the image in the Exe directory, we
can get the image with its name, no absolute path needed.

At last, if your baseform dll is strong named and placed in the GAC, then
it will not be in the same directory as the Exe, however, because it will
be load into the process space of application Exe, it will still use the
Exe's relative path to find the image file, we still should place the image
file in the Exe directory.

All in all, once we place the background image in the Exe file directory,
then use relative path to reference it, everything will work well. Like
this:
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
Image img=Image.FromFile("1.jpg");
if(img!=null)
{
this.BackgroundImage=img;
}
}

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

It's my pleasure to help you

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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