简体   繁体   中英

Aligning text of TextBox in c# Right and Bottom

I'm making a calculator in c#. I know the logic required to make a calculator. But the problem I'm facing is with the UI, I want to make the text in my TextBox Right and Bottom, while there is TextAlign property which makes the text in the TextBox align to right, I'm having trouble making it align to the bottom?.I really tried finding an answer.

在此处输入图片说明

but I want something like this

在此处输入图片说明

Also how to move the text in the textbox slightly upper when I press any operator?

Assuming the fact that you only use the TextBox for displaying the user input, a Label will allow for better use of what you want.

The Label supports a wider use of TextAlign so you could use

Label1.TextAlign = ContentAlignment.BottomRight;

If you want to create multiple lines inside the label, you can use Environment.NewLine to achieve that for example. But a StringBuilder and using AppendLine will probably work too.

If you really need to use a TextBox to achieve your needs, your best option would probably be to write a custom TextBox which supports your wanted text align.

Think this is possible with a RichTextBox but it would be a long work around. I would suggest using a Label . To align the text to the bottom right in a label you can use:

label.TextAlign = ContentAlignment.BottomRight;

To change the look of the Label you can use:

label.BackColor = Color.White;
label.BorderStyle = BorderStyle.FixedSingle;

To change the label from looking like a single line:

label.AutoSize = false;
label.Size = new Size(100,100)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM