Hi, Folks.
I Have a form that has 5 buttons to deal with information that will be passed to a DataBase: New, Edit, Delete, Save and Cancel. Normally Save and Cancel are disabled and the others are enabled. When user presses New (for example), The 3 first become disabled; Save and Cancel become enabled. And so on (I guess you have seen this). I've created a procedure that enables and disables the buttons according to the situation and it's working fine. Now I have many other forms in my application that have the same buttons and I need to use the same routine on them. My idea it to create the routine in another class which can be accessed by all forms. My problem is: how do I access the buttons that are in a form? I have already turned the buttons in the form public (instead of private). Now what? For example I have Form1 with buttons Bt_New, Bt_Edit, Br_Erase, Bt_Save and Bt_Cancel. The class I created is Routines.
In Routines:
Can anybody help me? Thanks.
I Have a form that has 5 buttons to deal with information that will be passed to a DataBase: New, Edit, Delete, Save and Cancel. Normally Save and Cancel are disabled and the others are enabled. When user presses New (for example), The 3 first become disabled; Save and Cancel become enabled. And so on (I guess you have seen this). I've created a procedure that enables and disables the buttons according to the situation and it's working fine. Now I have many other forms in my application that have the same buttons and I need to use the same routine on them. My idea it to create the routine in another class which can be accessed by all forms. My problem is: how do I access the buttons that are in a form? I have already turned the buttons in the form public (instead of private). Now what? For example I have Form1 with buttons Bt_New, Bt_Edit, Br_Erase, Bt_Save and Bt_Cancel. The class I created is Routines.
In Routines:
C#:
public void buttons(int Op)
{
if (op == 1)
{
Bt_New.Enabled = false;
Bt_Edit.Enabled = false;
Bt_Erase.Enabled = false;
Bt_Save.Enabled = true;
Bt_Cancel.Enabled = true;
}
else if (op == 2)
{
Bt_New.Enabled = true;
Bt_Edit.Enabled = true;
Bt_Erase.Enabled = true;
Bt_Save.Enabled = false;
Bt_Cancel.Enabled = false;
}
}
Last edited by a moderator: