IF PEMSTATUS(oObject, "MyCustumProperty",5) AND oObject.MyCustumProperty>
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Reflection; namespace ReflectionTest { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox textBox4; private System.Windows.Forms.TextBox textBox5; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox; private System.Windows.Forms.TextBox SomeTextBox; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TextBox textBox6; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox(); this.textBox5 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.textBox = new System.Windows.Forms.TextBox(); this.SomeTextBox = new System.Windows.Forms.TextBox(); this.panel1 = new System.Windows.Forms.Panel(); this.textBox6 = new System.Windows.Forms.TextBox(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(0, 0); this.label1.Name = "label1"; this.label1.TabIndex = 0; this.label1.Text = "label1"; // // label2 // this.label2.Location = new System.Drawing.Point(0, 32); this.label2.Name = "label2"; this.label2.TabIndex = 1; this.label2.Text = "label2"; // // label3 // this.label3.Location = new System.Drawing.Point(0, 64); this.label3.Name = "label3"; this.label3.TabIndex = 2; this.label3.Text = "label3"; // // label4 // this.label4.Location = new System.Drawing.Point(0, 96); this.label4.Name = "label4"; this.label4.TabIndex = 3; this.label4.Text = "label4"; // // label5 // this.label5.Location = new System.Drawing.Point(0, 128); this.label5.Name = "label5"; this.label5.TabIndex = 4; this.label5.Text = "label5"; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(120, 0); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(152, 20); this.textBox1.TabIndex = 5; this.textBox1.Text = "textBox1"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(120, 32); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(152, 20); this.textBox2.TabIndex = 6; this.textBox2.Text = "textBox2"; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(120, 56); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(152, 20); this.textBox3.TabIndex = 7; this.textBox3.Text = "textBox3"; // // textBox4 // this.textBox4.Location = new System.Drawing.Point(120, 88); this.textBox4.Name = "textBox4"; this.textBox4.Size = new System.Drawing.Size(152, 20); this.textBox4.TabIndex = 8; this.textBox4.Text = "textBox4"; // // textBox5 // this.textBox5.Location = new System.Drawing.Point(120, 120); this.textBox5.Name = "textBox5"; this.textBox5.Size = new System.Drawing.Size(152, 20); this.textBox5.TabIndex = 9; this.textBox5.Text = "textBox5"; // // button1 // this.button1.Location = new System.Drawing.Point(192, 224); this.button1.Name = "button1"; this.button1.TabIndex = 10; this.button1.Text = "Change texts"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox // this.textBox.Location = new System.Drawing.Point(128, 152); this.textBox.Name = "textBox"; this.textBox.TabIndex = 11; this.textBox.Text = "textBox"; this.textBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox_KeyPress); // // SomeTextBox // this.SomeTextBox.Location = new System.Drawing.Point(56, 184); this.SomeTextBox.Name = "SomeTextBox"; this.SomeTextBox.TabIndex = 12; this.SomeTextBox.Text = "Sometextbox"; // // panel1 // this.panel1.Controls.Add(this.textBox6); this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.panel1.Location = new System.Drawing.Point(0, 410); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(568, 100); this.panel1.TabIndex = 13; // // textBox6 // this.textBox6.Location = new System.Drawing.Point(48, 32); this.textBox6.Name = "textBox6"; this.textBox6.TabIndex = 0; this.textBox6.Text = "textBox6"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(568, 510); this.Controls.Add(this.panel1); this.Controls.Add(this.SomeTextBox); this.Controls.Add(this.textBox); this.Controls.Add(this.button1); this.Controls.Add(this.textBox5); this.Controls.Add(this.textBox4); this.Controls.Add(this.textBox3); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Form1"; this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void SetUsingReflection(int start,int end,string prefix) { for(int i=start;i<=end;i++) { string cMember = "textBox"+i.ToString(); TextBox member = (TextBox)this.GetType().InvokeMember(cMember, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetField, null,this,new object [] {}); member.Text = prefix+i.ToString(); } } private Control FindObjectByCollection(string objectName) { foreach(System.Windows.Forms.Control ctl in this.Controls) { if (ctl.Name.IndexOf(objectName) == 0) return ctl; } return null; } private Control FindObjectByReflection(string objectName) { try { Object o = this.GetType().InvokeMember(objectName, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetField, null,this,new object [] {}); return (Control)o; } catch { return null; } } private void button1_Click(object sender, System.EventArgs e) { /* for(int i=1;i<=3;i++) { Control ctl = FindObjectByCollection("textBox"+i.ToString()); if ( ctl != null ) ctl.Text="Hello "+i.ToString(); } for(int i=4;i<=6;i++) { Control ctl = FindObjectByReflection("textBox"+i.ToString()); if ( ctl != null ) ctl.Text="Hello "+i.ToString(); } */ //FindObjectByCollection("textBox4").Text="Hello 4"; //FindObjectByReflection("textBox3").Text="Hello 3"; //SetUsingControlsCollection(1,3,"Controls"); //SetUsingReflection(4,6,"Reflection"); //MemberInfo[] arrayMemberInfo = myForm.FindMembers(MemberTypes.All, // BindingFlags.NonPublic | BindingFlags.Instance, // new MemberFilter(DelegateToSearchCriteria), // cMember); } private void textBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (Control.ModifierKeys == Keys.Control && e.KeyChar == 22) { e.Handled = true; ((Control)sender).Text = "Ctrl+V pressed"; } } } }Cetin