using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Lesson11.
/// </summary>
public class Lesson11 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox lbList;
private System.Windows.Forms.PropertyGrid pgItem;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Lesson11()
{
//
// 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.lbList = new System.Windows.Forms.ListBox();
this.pgItem = new System.Windows.Forms.PropertyGrid();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lbList
//
this.lbList.Location = new System.Drawing.Point(0, 96);
this.lbList.Name = "lbList";
this.lbList.Size = new System.Drawing.Size(120, 173);
this.lbList.TabIndex = 0;
this.lbList.SelectedIndexChanged += new System.EventHandler(this.lbList_SelectedIndexChanged);
//
// pgItem
//
this.pgItem.CommandsVisibleIfAvailable = true;
this.pgItem.LargeButtons = false;
this.pgItem.LineColor = System.Drawing.SystemColors.ScrollBar;
this.pgItem.Location = new System.Drawing.Point(144, 96);
this.pgItem.Name = "pgItem";
this.pgItem.Size = new System.Drawing.Size(136, 168);
this.pgItem.TabIndex = 2;
this.pgItem.Text = "propertyGrid1";
this.pgItem.ViewBackColor = System.Drawing.SystemColors.Window;
this.pgItem.ViewForeColor = System.Drawing.SystemColors.WindowText;
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.miEdit_Insert_Click);
//
// Lesson11
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.pgItem);
this.Controls.Add(this.lbList);
this.Name = "Lesson11";
this.Text = "Lesson11";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Lesson11());
}
private void miEdit_Insert_Click(object sender, System.EventArgs e)
{
lbList.Items.Add(new TestObject());
}
private void lbList_SelectedIndexChanged(object sender, System.EventArgs e)
{
pgItem.SelectedObject = lbList.SelectedItem;
}
}
/// <summary>
/// TestObject will be used to test the PropertyGrid
/// </summary>
public class TestObject
{
private static int iCount=0;
private string strName = null;
public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}
private Image imPicture = null;
public Image Picture
{
get
{
return imPicture;
}
set
{
imPicture = value;
}
}
public TestObject()
{
strName = iCount.ToString();
iCount++;
}
public override string ToString()
{
return strName;
}
}
}