在我维护的项目中,原始开发人员将此代码放在主窗体的Designer.cs文件的顶部:
private void MemberListBox_Load()
{
DataTable dtMembers = null;
SQLServer sqlDAL = null;
sqlDAL = new SQLServer(Properties.Settings.Default.BIDataConnection);
sqlDAL.CommandTimeout = 120;
DataSet dsMember = sqlDAL.runSQLDataSet("select PoisonToe from PlatypusData..Members where abs(ActiveFlg)=1 Order By PoisonToe", "Members");
dtMembers = dsMember.Tables[0];
MemberListBox.DataSource = dtMembers;
MemberListBox.DisplayMember = "PoisonToe";
foreach (DataRow unitDPRow in dtMembers.Rows)
{
string x = unitDPRow[0].ToString();
MemberListBox.SetItemChecked(MemberListBox.FindString(x), true);
}
}
对于此类代码,MainForm.cs不是更常用的位置吗?在MainForm.Designer.cs中使用它的目的是什么?我应该把它移到MainForm.cs吗?