Control query between different forms - mode one ====================================== ======================== New creation is named: ucformcollector.cs ================= ====================================================== @ystem; use System.collections; using system.windows.forms;
Namespace queryform1 {
// Query the form of the form PUBLIC ENUM ucQuerytype {form, control}
///
// Form an array collection public static arraylist formlist {get {return m_formlist;}}
///
m_formlist.add (p_form.handle); attachevent (p_form);}
///
///
While (myenumerator.movenext ()) {
Currform = (form) form.fromhandle ((system.intptr) Myenumerator.current;
IF (currform.name.tolower () == p_formname.tolower ()) {Findform = Currform;}}
Return FindForm;
}
///
IF (Currform! = null) {for (Control Ctr in Currform.Controls) {if (ctr.name.tolower () == p_controlname.tolower ()) {FINDCONTROL = Ctr;}}}
Return FindControl;
}
///
// Release after the form is closed, the form of the form of the form Private Static Void ONFORMCLOSEDREMOVEITEM (Object Sender, System.EventArgs E) {Removeform ((Form) Sender);}
}} ================================================ ============== New form name is: form1.cs =================================================== ============================================ Using system; use system.drawing; useing system.collections; using System.componentmodel; Using System.Windows.Forms; Using System.Threading; Namespace Queryform1 {///
//inquiry mode
Ucquerytype querytype = new ucquerytype ();
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();
// / / TODO: Add any constructor code after INITIALIZEComponent call //
UcFormCollector.Addform (this);
Thread T1 = New Thread (New ThreadStart (Showform2)); Thread T2 = New Thread (New ThreadStart (ShowForm3));
T1.Start (); t2.start ();
}
Private void showform2 () {Application.run (New Form2 ());
Private void showform3 () {Application.run (New Form3 ());} ///
#REGION Windows Form Designer The code ///
/// summary> private void InitializeComponent () {this.textBox1 = new System.Windows.Forms.TextBox (); this.textBox2 = new System.Windows.Forms.TextBox (); this.button1 = new System. Windows.Forms.Button (); this.radioButton1 = new System.Windows.Forms.RadioButton (); this.radioButton2 = new System.Windows.Forms.RadioButton (); this.SuspendLayout (); // // textBox1 / / This.TextBox1.Location = new system.drawing.point (24, 40); this.textbox1.name = "textbox1"; this.TextBox1.tabindex = 0; this.textBox1.text = "formname"; // / / textbox2 // this.textBox2.Location = new system.drawing.point (24, 88); this.textBox2.name = "textbox2"; this.textBox2.tabindex = 1; this.TextBox2.text = "controlname"; // // button1 // this.button1.Location = new system.drawing.point (24, 200); this.button1.name = "button1"; this.button1.tabindex = 2; this.button1.text = " Query "; this.button1.click = new system.eventhandler (this.button1_click); // // radio Button1 // this.radioButton1.Checked = true; this.radioButton1.Location = new System.Drawing.Point (24, 136); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing. Size (136, 24); this.radioButton1.TabIndex = 3; this.radioButton1.TabStop = true; this.radioButton1.Text = "query form (form)"; this.radioButton1.CheckedChanged = new System.EventHandler ( THIS.RADIOBUTTON1_CHECKEDCHANGED; //// Radiobutton2 // this.radiobutton2.location = new system.drawing.point (24, 160); this.Radiobutton2.name = "
Radiobutton2 "; this.Radiobutton2.size = new system.drawing.size (192, 24); this.Radiobutton2.tabindex = 4; this.Radiobutton2.text =" Query the control on the form; this.Radiobutton2 .CheckedChanged = new System.EventHandler (this.radioButton2_CheckedChanged); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size (6, 14); this.ClientSize = new System.Drawing.Size (292, 273); this.controls.add (this.controls.add (this.radiobutton1); this.controls.add (this.button1); this.Controls.add (this.TextBox2); this.controls .Add (THIS.TEXTBOX1); this.Name = "Form1"; this.text = "Form and control query (form collection method)"; this.ResumeLayout (false);}
#ndregion
Static void main () {Application.run (New Form1 ());}
Private void button1_click (object sender, system.eventargs e) {string formName = textbox1.text.trim (); string controlname = textBox2.text.trim (); string str = ""
Str = "QueryType:" querytype.totring () "/ n / n";
IF (querytype == ucquerytype.form) {form currform = ucformollector.queryform (Formname);
IF (currform == null) {str = "Object is not all!";} else {str = "text is: /" currform.text "/" ";}} else f (querytype == Ucquerytype.control) {Control currcontrol = ucformcollector.queryControl (FormName, ControlName);
IF (currcontrol == null) {str = "Object is not found!";} else {str = "text is: /" currcontrol.text "/";}}
Messagebox.show (str);
Private void radiobutton1_checkedchanged (Object sender, system.eventargs e) {querytype = ucQuerytype.form;}
Private void radiobutton2_checkedchanged (object sender, system.eventargs e) {querytype = ucQuerytype.control;}
}} ================================================ ============== The new form is named: form2.cs ====================================================== ============================================ Using system; use system.drawing; useing system.collections; using System.componentmodel; using system.windows.forms;
Summary description of Namespace queryform1 {///
Public Form2 () {// // Windows Form Designer Support for // InitializationComponent ();
// // Todo: Add any constructor code // ucformcollector.addform (this); UcFormCollector.addform (this); // Duplicate invalid
}
///
} #Endregion
}} ================================================ ============== The new form is named: form3.cs ========================== ============================================ Using system; use system.drawing; useing system.collections; using Summary for system.componentmodel; use system.windows.forms; namespace queryform1 {///
Public Form3 () {// // Windows Form Designer Support for // InitializationComponent ();
// / / TODO: Add any constructor code after INITIALIZEComponent call //
UcFormCollector.Addform (this);
}
///
#REGION Windows Form Designer The code ///