Search code examples
c#user-interfacetextbox

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.

enter image description here

but I want something like this

enter image description here

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


Solution

  • 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.