I am new to c# programming and u might feel its very simple ... I am using menu bar(tool strip) with Add, update,delete, cancel and close buttons... In add button i have....
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
I want to add same code in almost 200+ forms. can anyone tell me what i suppose to do for it. Is there any user control or master control like asp.net in c# so that common code can be kept aside and called when its necessary... because if i put the NewSavebtn() and other methods in different class say class1 and try to call it from form1 like...
class1 c1 =new class1(this);
c1.NewSavebtn(this);
It does not work.... Thnks in advance....