Calling properties of one Form1 into another Form2.
-
Hi All, I have two forms, Form1 and Form2. Form1 has a tab control with tab name "A". I want to enable/disable this tab from Form2. How to do this?
A reasonably simple solution is to put a public boolean variable somewhere, and changing it in form2. Then choose a suitable event (for example
GotFocus
) in Form1 and based on the variable enable or disable your tab.My advice is free, and you may get what you paid for.
-
Hi All, I have two forms, Form1 and Form2. Form1 has a tab control with tab name "A". I want to enable/disable this tab from Form2. How to do this?
You cannot Enable / Disbale a tab directly. It does not have a property for this. The recommended method on MSDN is to handle the TabControl SelectedIndexChanged event. you will need to have a flag somewhere that you can set to reflect the state of the tab (enabled/Disabled) and then check in this event which tab you are on and then move to another tab if you try to select it when it is disabled. Search google for "How to: Disable Tab Pages" and you will find the article at MSDN. Dave
-
A reasonably simple solution is to put a public boolean variable somewhere, and changing it in form2. Then choose a suitable event (for example
GotFocus
) in Form1 and based on the variable enable or disable your tab.My advice is free, and you may get what you paid for.
My implelentation is like this: In Form1, Code is: Sub Functioname() { GroupbBox1.Enabled = False } Now I want to enable this GroupBox1 through Form2 in following function: Sub FunctionEnable() { ''''' Code will come here } Please let me know how to call that GroupBox1 control so that I can use its properties in Form2. Regards R.S.
-
My implelentation is like this: In Form1, Code is: Sub Functioname() { GroupbBox1.Enabled = False } Now I want to enable this GroupBox1 through Form2 in following function: Sub FunctionEnable() { ''''' Code will come here } Please let me know how to call that GroupBox1 control so that I can use its properties in Form2. Regards R.S.
See the other reply to your question. P.S. Besides that it seems you are on the wrong forum.
My advice is free, and you may get what you paid for.
-
You cannot Enable / Disbale a tab directly. It does not have a property for this. The recommended method on MSDN is to handle the TabControl SelectedIndexChanged event. you will need to have a flag somewhere that you can set to reflect the state of the tab (enabled/Disabled) and then check in this event which tab you are on and then move to another tab if you try to select it when it is disabled. Search google for "How to: Disable Tab Pages" and you will find the article at MSDN. Dave
-
My implelentation is like this: In Form1, Code is: Sub Functioname() { GroupbBox1.Enabled = False } Now I want to enable this GroupBox1 through Form2 in following function: Sub FunctionEnable() { ''''' Code will come here } Please let me know how to call that GroupBox1 control so that I can use its properties in Form2. Regards R.S.
Do you have a reference to form1 in form2? If you do then just call the
Functioname
method directly. If not then change your structure to have a reference. If the forms are intrinsically linked like this then there is no point doing this with events.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Hi All, I have two forms, Form1 and Form2. Form1 has a tab control with tab name "A". I want to enable/disable this tab from Form2. How to do this?
-
-
You need a reference for Form1 in Form2 so you can directly manipulate its controls and set its properties.
Hi Shameel, I am sedning You the actual scenario where I am using multiple forms this: I have 2 forms, main Form1 and a loginform. I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis()....call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please tell me how to do this?? Hope my problem is clear..Thanks.
-
Hi Shameel, I am sedning You the actual scenario where I am using multiple forms this: I have 2 forms, main Form1 and a loginform. I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis()....call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please tell me how to do this?? Hope my problem is clear..Thanks.
To call a function on Form1, you need a reference to the form in your loginform. It depends on where you instantiate Form1 in your app. Assuming that you instantiate Form1 in loginform (since loginform should ideally be the first form that is loaded in your app from main() method), the code could be something like this:
Form1 form1 = new Form1();
form1.DoThis();
form1.Show(); -
To call a function on Form1, you need a reference to the form in your loginform. It depends on where you instantiate Form1 in your app. Assuming that you instantiate Form1 in loginform (since loginform should ideally be the first form that is loaded in your app from main() method), the code could be something like this:
Form1 form1 = new Form1();
form1.DoThis();
form1.Show(); -
my Form1 is the first form which get loaded. loginform is loaded on the click of a button on Form1. Pls tell me how to do this.
loginform.cs
//Reference to Form1
Form1 _form1;//Constructor
public loginform(Form1 form1) {
_form1 = form1;
}//Use Form1 referemce
public DoSomething() {
_form1.DoThat()
}Form1.cs
private button1_Click(...) {
loginform fLogin = new loginform(this);
loginform.ShowDialog();
} -
Do you have a reference to form1 in form2? If you do then just call the
Functioname
method directly. If not then change your structure to have a reference. If the forms are intrinsically linked like this then there is no point doing this with events.If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
Please see my requirement below carefully: need immediate help. I have 2 forms, main Form1 and a loginform. When I start the application, first "Form1" is loaded and then with a button click, user can load "loginform" if required to enable/disable some features/controls on Form1. The sequence is like this: 1) Load main form Form1 2) click a button on Form1 3) Load the loginform. 4) enter user/pwd and click OK button 5) enable/disable "GroupBox" control on Form1 if login sucessful. For this, I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public, which enables/disables the "GroupBox" control on Form1. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ' Function to enable/disable GroupBox control ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis().... 'call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please suggest me with a piece of code how to do this?? Please remember that Form1 is my main form which is loading first. If anyother way is there to make a password protected feature for GroupBox control in Form1, it will be highly appriciated. Hope my problem is clear..Thanks.