方法 'InitializeComponent' 中的代码由设计者生成,不应手动修改 [英] The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified

查看:83
本文介绍了方法 'InitializeComponent' 中的代码由设计者生成,不应手动修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在开始时加载我的 ComboBox,我在 InitializeComponent() 方法中使用了我的方法 LoadDataFromDB(),但是有一个警告说:

To load my ComboBox at the beginning I used the mine method LoadDataFromDB() in the InitializeComponent() method, but there is an warning says:

方法InitializeComponent"中的代码由设计器,不应手动修改

The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified

那么我可以在哪里加载我的 ComboBox?

推荐答案

使用表单的构造函数

public Form1()
{
    InitializeComponent();
    LoadDataFromDB();
}

或者(有时更好) Form.Load 事件处理程序(在设计器中双击表单时会自动添加):

Or (sometimes better) Form.Load event handler (it will be added automatically when you double-click form in designer):

private void Form1_Load(object sender, EventArgs e)
{
    LoadDataFromDB();
}

另一个选项是覆盖表单的 OnLoad 方法.

Another option is overriding OnLoad method of form.

注意:您看到此警告,因为 InitializeComponent 是由设计器生成的,当您在设计器中更改某些内容(添加一些控件,移动或调整某些控件的大小)时,它将完全重新生成,改变颜色等).因此,您对此方法所做的所有更改都将消失.

NOTE: You see this warning, because InitializeComponent is generated by designer, and it will be completely re-generated when you'll change something in designer (add some control, move or resize some control, change color etc). Thus all your changes to this method will gone.

这篇关于方法 'InitializeComponent' 中的代码由设计者生成,不应手动修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆