C# 获取属性Grid文本框
如何从指定字段获取PropertyGrid的文本框? 我需要这个文本框来设置指向文本结尾的指针C# 获取属性Grid文本框,c#,winforms,textbox,propertygrid,C#,Winforms,Textbox,Propertygrid,如何从指定字段获取PropertyGrid的文本框? 我需要这个文本框来设置指向文本结尾的指针 var num = txtBox.GetCharIndexFromPosition(Cursor.Position); txtBox.SelectionStart = num + 1; txtBox.SelectionLength = 0; 那么我怎样才能从PropertyGrid获得这个文本框呢? 此外,PropertyGrid中的属性是只读的。如果您希望光标正好位于文本框中最后一个字符的后面,则
var num = txtBox.GetCharIndexFromPosition(Cursor.Position);
txtBox.SelectionStart = num + 1;
txtBox.SelectionLength = 0;
那么我怎样才能从PropertyGrid获得这个文本框呢?
此外,PropertyGrid中的属性是只读的。如果您希望光标正好位于文本框中最后一个字符的后面,则可以使用以下代码(由
文本框的文本更改事件触发):
记住,它的位置总是在中间。
-----在KINGKING注释后更新
至于问题中的代码是指文本框
,我的答案集中在文本框
。尽管如此,KingKing是正确的,必须考虑属性Grid
。在这些行下面,我改编了您可以在中找到的代码,用于PropertyGrid
:
private void Form1_Load(object sender, EventArgs e)
{
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 = txtBox;
}
将txtBox
添加到propertyGrid1
后,其位置将更新,因此可以毫无问题地使用原始代码
总之,我们的想法不是在PropertyGrid
中查找TextBox
,而是直接访问TextBox
控件(在运行时添加到PropertyGrid
)。您需要在文本框中选择文本吗?OP
如何访问txtBox
?他想访问与PropertyGrid
中的字段相对应的特定文本框。
private void Form1_Load(object sender, EventArgs e)
{
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 = txtBox;
}