1: using System;
2: using System.Drawing;
3: using System.Collections;
4: using System.ComponentModel;
5: using System.Windows.Forms;
6: using System.Data;
7:
8: namespace WindowsApplication1
9: {
10: /// <summary>
11: /// Summary description for Lesson11.
12: /// </summary>
13: public class Lesson11 : System.Windows.Forms.Form
14: {
15: private System.Windows.Forms.ListBox lbList;
16: private System.Windows.Forms.PropertyGrid pgItem;
17: private System.Windows.Forms.Button button1;
18: /// <summary>
19: /// Required designer variable.
20: /// </summary>
21: private System.ComponentModel.Container components = null;
22:
23: public Lesson11()
24: {
25: //
26: // Required for Windows Form Designer support
27: //
28: InitializeComponent();
29:
30: //
31: // TODO: Add any constructor code after InitializeComponent call
32: //
33: }
34:
35: /// <summary>
36: /// Clean up any resources being used.
37: /// </summary>
38: protected override void Dispose( bool disposing )
39: {
40: if( disposing )
41: {
42: if (components != null)
43: {
44: components.Dispose();
45: }
46: }
47: base.Dispose( disposing );
48: }
49:
50: #region Windows Form Designer generated code
51: /// <summary>
52: /// Required method for Designer support - do not modify
53: /// the contents of this method with the code editor.
54: /// </summary>
55: private void InitializeComponent()
56: {
57: this.lbList = new System.Windows.Forms.ListBox();
58: this.pgItem = new System.Windows.Forms.PropertyGrid();
59: this.button1 = new System.Windows.Forms.Button();
60: this.SuspendLayout();
61: //
62: // lbList
63: //
64: this.lbList.Location = new System.Drawing.Point(0, 96);
65: this.lbList.Name = "lbList";
66: this.lbList.Size = new System.Drawing.Size(120, 173);
67: this.lbList.TabIndex = 0;
68: this.lbList.SelectedIndexChanged += new System.EventHandler(this.lbList_SelectedIndexChanged);
69: //
70: // pgItem
71: //
72: this.pgItem.CommandsVisibleIfAvailable = true;
73: this.pgItem.LargeButtons = false;
74: this.pgItem.LineColor = System.Drawing.SystemColors.ScrollBar;
75: this.pgItem.Location = new System.Drawing.Point(144, 96);
76: this.pgItem.Name = "pgItem";
77: this.pgItem.Size = new System.Drawing.Size(136, 168);
78: this.pgItem.TabIndex = 2;
79: this.pgItem.Text = "propertyGrid1";
80: this.pgItem.ViewBackColor = System.Drawing.SystemColors.Window;
81: this.pgItem.ViewForeColor = System.Drawing.SystemColors.WindowText;
82: //
83: // button1
84: //
85: this.button1.Location = new System.Drawing.Point(192, 48);
86: this.button1.Name = "button1";
87: this.button1.TabIndex = 3;
88: this.button1.Text = "button1";
89: this.button1.Click += new System.EventHandler(this.miEdit_Insert_Click);
90: //
91: // Lesson11
92: //
93: this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
94: this.ClientSize = new System.Drawing.Size(292, 273);
95: this.Controls.Add(this.button1);
96: this.Controls.Add(this.pgItem);
97: this.Controls.Add(this.lbList);
98: this.Name = "Lesson11";
99: this.Text = "Lesson11";
100: this.ResumeLayout(false);
101:
102: }
103: #endregion
104:
105: /// <summary>
106: /// The main entry point for the application.
107: /// </summary>
108: [STAThread]
109: static void Main()
110: {
111: Application.Run(new Lesson11());
112: }
113:
114: private void miEdit_Insert_Click(object sender, System.EventArgs e)
115: {
116: lbList.Items.Add(new TestObject());
117: }
118:
119: private void lbList_SelectedIndexChanged(object sender, System.EventArgs e)
120: {
121: pgItem.SelectedObject = lbList.SelectedItem;
122: }
123: }
124: /// <summary>
125: /// TestObject will be used to test the PropertyGrid
126: /// </summary>
127: public class TestObject
128: {
129: private static int iCount=0;
130: private string strName = null;
131: public string Name
132: {
133: get
134: {
135: return strName;
136: }
137: set
138: {
139: strName = value;
140: }
141: }
142: private Image imPicture = null;
143: public Image Picture
144: {
145: get
146: {
147: return imPicture;
148: }
149: set
150: {
151: imPicture = value;
152: }
153: }
154: public TestObject()
155: {
156: strName = iCount.ToString();
157: iCount++;
158: }
159: public override string ToString()
160: {
161: return strName;
162: }
163: }
164: }
165: