About the control query between different forms - mode two ====================================== ======================== New catename is named: ucformQueryExtender.cs ================= ===================================================== Using system; use system .Collections; using system.componentmodel; using system.windows.form
Namespace queryform2 {
/ / Query Event Entrusted Public Delegate Void QueryObjectEventHandler (UcQueryObjectProp P_Queryop); // Tune Event Entrusted Public Delegate Void CallbackeVentHandler (Object P_Object);
///
// Query public static void doquuery (ucqueryObjectprop p_queryop) {if (query! = Null) {query (p_queryop);}}
Public Static Event Callback; // Tonance Public Static Void Docallback (Object P_Object) {if (Callback! = NULL) {Callback (p_Object);}}
// Public object query method public static void findObject (Form p_currform, ucQueryObjectProp p_queryop) {
//
Ucquerytype querytype = p_queryop.querytype; string formName = p_queryop.formname; string controlname = p_queryryop.controlname;
//
Object FindObject = NULL;
if (! FormName.ToLower () = p_CurrForm.Name.ToLower ()) {return;} if (QueryType == UcQueryType.Form) // query form {FindObject = p_CurrForm;} else if (QueryType == UcQueryType.Control ) // Query control {Foreach (Control Ctr in p_currform.controls) {if (ctr.name.tolower () == ControlName.tolower ()) {FindObject = Ctr;}}}
UcformQueryExtendeer.docallback (FindObject);
}
// Query the form of the form PUBLIC ENUM ucQuerytype {form, control}
// Structure of the query parameter (Parameters in structure) public struct ucqueryObjectProp {public string formname; public string constroname;}};} PUBLIC STRING FORMNAME
} ==================================================== ============= New form name is: form1.cs =========================== ============================================ ingry system.drawing; use system.collections; using system.collections; using system.collections; using system.collections; .Componentmodel; using system.windows.form; system.threading;
A summary description of Namespace Queryform2 {///
Ucquerytype querytype = new ucquerytype ();
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();
// / / TODO: Add any constructor code after INITIALIZEComponent call //
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 (event registration callback mode)"; this.ResumeLayout (false);}
#ndregion
Static void main () {Application.run (New Form1 ());}
Private void button1_click (Object sender, system.eventargs e) {
UcQueryObjectProp Queryop = New ucqueryObjectProp ();
Queryop.QueryType = querytype; queryop.formname = textBox1.text.trim (); queryop.controlname = textbox2.text.trim ();
UcformQueryExtender.callback = new callbackendhandler (Callback);
UcformQueryExtender.doQuery (queryop);
UcformQueryExtender.callback - = New CallBackeVentHandler (Callback);
}
Private Void Callback (Object P_Object) {String Str = ""
Str = "QueryType:" querytype.totring () "/ n / n";
IF (p_Object == null) {str = "Object is not found!";} else {if (querytype == ucquerytype.form) {str = "text is: /" " ((form) p_Object). Text "/";} else if (querytype == ucquerytype.control) {str = "text is: /" " ((Control) p_object) .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;}}} ============================ ================================== New form name is: form2.cs ====== ============================================================================================================================================================================================================= ====== Using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.form;
A summary description of Namespace queryform2 {///
// // Todo: Add any constructor code // ucformQueryExtender.Query = new queryObjectEventHandler (ucformqueryextender_onquery);
}
Private void ucformQueryExtender_onquery (ucQueryObjectProp p_queryop) {ucformQueryExtender.findObject (this, p_queryop);}
///
#REGION Windows Form Designer The code ///
}} ================================================ ============== The new form is named: form3.cs ========================== ============================================ Using system; use system.drawing; useing system.collections; using Summary description of system.componentmodel; use system.windows.forms; namespace queryform2 {///
Public Form3 () {// // Windows Form Designer Support for // InitializationComponent ();
// / / TODO: Add any constructor code after INITIALIZEComponent call //
UcformQueryExtender.Query = New queryiryObjectEventHandler (ucformQueryExtender_onquery);
}
Private void ucformQueryExtender_onquery (ucQueryObjectProp p_queryop) {ucformQueryExtender.findObject (this, p_queryop);}
///
#REGION Windows Form Designer The code ///