写Form设计器尝试(二) PropertyGrid

切换到Form1的设计页面,往上面放一个SplitContainer,再在这个SplitContainer的右panel上放一个PropertyGrid,并将其Dock属性值设置成Fill。

切换到代码编辑界面,并将上篇输入的代码的最后一行改成:

//原来的最后一行
//this.Controls.Add(view);

//修改成下面的代码
this.splitContainer1.Panel1.Controls.Add(view);
this.propertyGrid1.SelectedObject = surface.ComponentContainer.Components[0];

这样就能在设计时Form的其他属性了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 C# PropertyGrid 实例: ```csharp using System.ComponentModel; using System.Windows.Forms; public class Person { public string Name { get; set; } public int Age { get; set; } public string Gender { get; set; } } public class MainForm : Form { private PropertyGrid propertyGrid; private Person person; public MainForm() { InitializeComponent(); InitializePerson(); InitializePropertyGrid(); } private void InitializeComponent() { this.propertyGrid = new PropertyGrid(); this.SuspendLayout(); // // propertyGrid // this.propertyGrid.Dock = DockStyle.Fill; this.propertyGrid.Location = new System.Drawing.Point(0, 0); this.propertyGrid.Name = "propertyGrid"; this.propertyGrid.Size = new System.Drawing.Size(284, 262); this.propertyGrid.TabIndex = 0; // // MainForm // this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.propertyGrid); this.Name = "MainForm"; this.Text = "PropertyGrid Example"; this.ResumeLayout(false); } private void InitializePerson() { person = new Person(); person.Name = "John Doe"; person.Age = 30; person.Gender = "Male"; } private void InitializePropertyGrid() { propertyGrid.SelectedObject = person; } } ``` 在此示例中,我们创建了一个名为“Person”的类,该类具有三个属性:Name、Age 和 Gender。然后,我们创建一个名为“MainForm”的窗体,并在其中添加一个 PropertyGrid 控件。在 MainForm 的构造函数中,我们初始化了 Person 对象并将其分配给 PropertyGrid 的 SelectedObject 属性。这将使 PropertyGrid 显示 Person 对象的所有属性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值