• 12
• 10
• 10
• 13
• 10

# [.net] windows form properties in visual studio... :(

This topic is 3889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to get a multiline textbox to take up the entire client area of a window. Is there any way to do this using visual studio's property panel, or does it have to be done in code?

##### Share on other sites
Set the Dock property of the textbox to Fill (it's the center button in the property drop down). It's under the Layout category in the properties pane.

##### Share on other sites
thanks, that solved it! i rated you up.

##### Share on other sites

i want to edit a single line in a textbox. do i have to copy the entire contents in order to do this? msdn says:

Quote:
 To get a writable collection of lines, use code similar to the following: textBox1.Lines = new string[] { "abcd" };

what does that mean?

##### Share on other sites
Quote:
Original post by 020644

i want to edit a single line in a textbox. do i have to copy the entire contents in order to do this? msdn says:

Quote:
 To get a writable collection of lines, use code similar to the following: textBox1.Lines = new string[] { "abcd" };

what does that mean?

Are you trying to get the line or change the line?

string a = textBox1.Lines[0];  // that will get the first line from the text box.a = a.ToUpper();  // change the string to all Upper case.textBox1.Lines[0] = a;  // set first line equal to the Upper case string.///////////////////////////////////////////////////////////////////// if you want to get all the lines from the text box...string[] lines = textBox1.Lines;  // get all the lines from the text box.foreach(string line in lines){    line = line.ToUpper();  // Set all the lines to upper case}textBox1.Lines = lines;  //Set the textbox lines to lines[]

Does that help?
theTroll

##### Share on other sites
well, i'm trying to implement auto-indent using a textbox. it's incredibly difficult, however, because the newline character is added after i catch the keypress event for 'enter'.

even if i ever get it working, i'm only editing one line at a time in the textbox. it seems like a waste to copy the entire contents of the file each time the user presses enter. the quote from msdn above indicates that it's possible to get a mutable list of lines.

##### Share on other sites
I only skimmed over this thread, but an alternative might be to use the Textbox.Paste(string) method. This allows you to insert stuff at the cursor position, which may be more efficient and/or elegant. There's probably a way to cancel/consume the key event, so you could use this method to manually insert "\r\n\t\t" or something instead of allowing the textbox to add the enter. This page seems to contain more details on how to cancel the event (last reply at the bottom).

Hope this is what you were looking for :)

##### Share on other sites
thanks for your help, unfortunately there is no 'handled' property for PreviewKeyDownEventArgs!

how can i prevent the newline from being added automaticall?

edit: textbox.suppresskeypress works! i hope this can help someone else with the same problem. thanks for your help everyone.