Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any user control or master control in C# or any other way to call reusable code
    primarykey
    data
    text
    <p>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....</p> <pre><code>private void btn_Add_Click(object sender, EventArgs e) { NewSavebtn(); } public void NewSavebtn() { if (btn_Add.Text == "&amp;New") { btn_Add.Text = "&amp;Save"; btn_Edit.Enabled = false; btn_Delete.Enabled = false; txtDetailName.Enabled = true; TxtHeadName.Enabled = true; UnLock(); } else if (btn_Add.Text == "&amp;Save") { save_data(); Lock(); btn_Add.Text = "&amp;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 </code></pre> <p>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...</p> <pre><code>class1 c1 =new class1(this); c1.NewSavebtn(this); </code></pre> <p>It does not work.... Thnks in advance....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload