Start a new line in wpf textbox

2019-02-16 04:15发布

I created a small GUI with WPF, containing a Textbox. I want the user to have the ability to start a new line . How do I let the user start a new line in the WPF textbox (with \n or \r)? I want the user to be able to start a new line by pressing "enter".

3条回答
看我几分像从前
2楼-- · 2019-02-16 04:34

The textbox control has an "AcceptsReturn" property (True/False) that you need to set to True.

You can set it in the Visual Studio IDE Properties box or you can set it within the code.

textbox1.AcceptsReturn = true;
查看更多
戒情不戒烟
3楼-- · 2019-02-16 04:41

In addition to the AcceptReturn = true property, if the user wants to start a new line by pressing the enter key you will need to check these properties:

  1. IsReadOnly should be False. If you set this to True, then obviously the Enter key won't work.
  2. Verify the control containing the TextBox is not clipping the TextBox, else it will appear that the Enter key did not work.
查看更多
太酷不给撩
4楼-- · 2019-02-16 04:45

have you try set on your textbox following property:

TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible" (or auto)
AcceptsReturn="True"
查看更多
登录 后发表回答