简体   繁体   中英

reflecting an object values which is in the memory on the GUI?

I have an object in the memory and I want to link this object with GUI component and I want this component to mirror the object status(values)....
ie I want to see the object values that is in the memory right now and I want the GUI to reflect the object status always
how can I do this?

This is a very common pattern in development and is called Data Binding. .NET has some great support for data binding, it is a large topic and too big for a simple answer here. But here is a link to an MSDN article that will get you started.

http://msdn.microsoft.com/en-us/library/ms752347.aspx

If you are using WinForms, the PropertyGrid component is what you want:

public Form1() {

   // The initial constructor code goes here.

   PropertyGrid propertyGrid1 = new PropertyGrid();
   propertyGrid1.CommandsVisibleIfAvailable = true;
   propertyGrid1.Location = new Point(10, 20);
   propertyGrid1.Size = new System.Drawing.Size(400, 300);
   propertyGrid1.TabIndex = 1;
   propertyGrid1.Text = "Property Grid";

   this.Controls.Add(propertyGrid1);

   propertyGrid1.SelectedObject = textBox1;
}

Here, textBox1 is being "inspected". It can be any object. It displays it like the property inspector you see in Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM