我是 C# 编程的新手,你可能会觉得它非常简单......我正在使用带有添加、更新、删除、取消和关闭按钮的菜单栏(工具条)......在添加按钮中我有......
private void btn_Add_Click(object sender, EventArgs e)
{
NewSavebtn();
}
public void NewSavebtn()
{
if (btn_Add.Text == "&New")
{
btn_Add.Text = "&Save";
btn_Edit.Enabled = false;
btn_Delete.Enabled = false;
txtDetailName.Enabled = true;
TxtHeadName.Enabled = true;
UnLock();
}
else if (btn_Add.Text == "&Save")
{
save_data();
Lock();
btn_Add.Text = "&Add";
btn_Edit.Enabled = true;
btn_Delete.Enabled = true;
ClearAll();
txtDetailName.Enabled = false;
}
else
MessageBox.Show("cant save data");
}
#region Clear Lock Unlock
public void ClearAll()
{
foreach (Control ctl in this.Controls)
{
if (ctl is TextBox || ctl is ComboBox)
{
ctl.Text = "";
}
}
}
public void Lock()
{
foreach (Control ctl in this.Controls)
{
if (ctl is TextBox || ctl is ComboBox)
{
ctl.Enabled=false ;
}
}
}
public void UnLock()
{
foreach (Control ctl in this.Controls)
{
if (ctl is TextBox || ctl is ComboBox)
{
ctl.Enabled=true ;
}
}
}
#endregion
我想以近 200 多种形式添加相同的代码。谁能告诉我我想为它做些什么。是否有任何用户控件或主控件,如 c# 中的 asp.net,以便可以将公共代码放在一边并在必要时调用......因为如果我将 NewSavebtn() 和其他方法放在不同的类中说 class1 并尝试调用它来自form1,例如...
class1 c1 =new class1(this);
c1.NewSavebtn(this);
它不起作用....提前谢谢....