c# - Get PropertyGrid TextBox -


how can propertygrid's textbox specified field? need textbox set pointer end of text.

var num = txtbox.getcharindexfromposition(cursor.position); txtbox.selectionstart = num + 1; txtbox.selectionlength = 0; 

so how can textbox propertygrid? also, property in propertygrid read-only.

if want cursor located right after last character written in textbox, can rely on following code (triggered textchanged event of textbox):

private void txtbox_textchanged(object sender, eventargs e) {     int newx = txtbox.location.x + textrenderer.measuretext(txtbox.text, txtbox.font).width;     int newy = txtbox.bottom - txtbox.height / 2;     if (newx > txtbox.location.x + txtbox.width)     {         newx = txtbox.location.x + txtbox.width;     }     cursor.position = this.pointtoscreen(new point(newx, newy)); } 

bear in mind y position in middle.

----- update after kingking comment

as far code in question referred textbox, focused answer on textbox. nonetheless, kingking right , propertygrid has brought consideration. below these lines adapted code can find in msdn 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; } 

after txtbox added propertygrid1, position updated , original code can used without problem.

in summary, idea not looking textbox inside propertygrid, accessing directly textbox control (which added @ runtime propertygrid).


Comments