how to pass a handler to another form
-
dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.
-
dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.
One of the ways is: From Form1 get Height and Width of Form2 by:
Form2 frm2 = new Form2();
int height = frm2.Height;
int width = frm2.Width;
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.
-
Assuming you have a reference to the other form then you can access its properties.
It's time for a new signature.
thanks first. if i have such dialogs
InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
InspectionResultDialog m_RltDlg = new InspectionResultDialog();
Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.
-
thanks first. if i have such dialogs
InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
InspectionResultDialog m_RltDlg = new InspectionResultDialog();
Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.
Then use internal static variables [^]
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
thanks first. if i have such dialogs
InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
InspectionResultDialog m_RltDlg = new InspectionResultDialog();
Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.
-
thanks first. if i have such dialogs
InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
InspectionResultDialog m_RltDlg = new InspectionResultDialog();
Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.
If you want to access an object instance from anywhere, the Singleton pattern[^] is the recommended method. Are you sure you want to do this for three forms though? Static/Singletons have their place and uses but can often be the result of poor design, poor undestanding of OOP, lazyness. I'm not saying "don't", just be sure that it is actually required!
Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Keep the references to your dialogs or forms in your main form class or make them global so that you can refer to them in any module.
It's time for a new signature.
-
how to keep the reference for dialog or forms in my main form class? could u give me an example?thanks
I don't quite understand your problem with this. Just add a variable of the correct form type to your main form, create the new form and save the reference. You could do this in your constructor or create a special method that does it on demand; either way your other forms will remain until you destroy them. Then you can use that from anywhere in your main form code.
It's time for a new signature.