EidolonMK
EidolonMK

Reputation: 313

Set background image and other properties of all forms

I'd like to know how is it possible to set a background image for all my windows forms, also other properties such as disable controlbox, minimizebox, etc. I read from somewhere I could use inheritance, how is this possible? Should I create a base class with all these settings? So far I've just been able to import my image into the resources

Upvotes: 1

Views: 93

Answers (3)

Paolo Costa
Paolo Costa

Reputation: 1989

Sure you can use inheritance, you can have a class and make all the Form classes inherit from the base one. Here's an example:

public partial class Form1 : BaseForm
{
    public Form1()
    {
        InitializeComponent();
    }
}

public class BaseForm : Form
{
    protected override void OnLoad(EventArgs e)
    {
        this.ControlBox = false;
        this.MinimizeBox = false;
        this.MaximizeBox = false;
        this.BackColor = Color.Cyan;
        base.OnActivated(e);
    }
}

Upvotes: 1

Philip Stuyck
Philip Stuyck

Reputation: 7467

Yes it is possible, and it has a name : visual inheritance. You can google that term and get a lot of useful information on how to do it.

You can start here : https://msdn.microsoft.com/en-us/library/bx1155fz%28v=vs.110%29.aspx

The idea is basically the same as with any other inheritance. So it is not difficult at all.

Upvotes: 0

Dgan
Dgan

Reputation: 10285

  1. Create Class as MyForm Inherited from System.Windows.Forms.
  2. Apply Your All Properties to this MyForm then You can Use this MyForm in your all other Forms.

Upvotes: 0

Related Questions