简体   繁体   English

设置所有表格的背景图片和其他属性

[英]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? 我想知道如何为所有Windows窗体以及其他属性(如禁用控制箱,最小化箱等)设置背景图像。我从可以使用继承的地方读取信息,这怎么可能? Should I create a base class with all these settings? 是否应该使用所有这些设置创建基类? So far I've just been able to import my image into the resources 到目前为止,我已经能够将我的图像导入资源中

Sure you can use inheritance, you can have a class and make all the Form classes inherit from the base one. 当然,您可以使用继承,您可以拥有一个类,并使所有Form类都从基类继承。 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);
    }
}
  1. Create Class as MyForm Inherited from System.Windows.Forms . 创建类为MyForm继承自System.Windows.Forms
  2. Apply Your All Properties to this MyForm then You can Use this MyForm in your all other Forms. 将您的所有属性应用于此MyForm,然后您可以在所有其他表单中使用此MyForm

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. 您可以在Google上搜索该术语,并获取有关如何操作的大量有用信息。

You can start here : https://msdn.microsoft.com/en-us/library/bx1155fz%28v=vs.110%29.aspx 您可以从这里开始: 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. 因此,这一点都不困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM