how to use ContentAlignment.BottomRight

895 views Asked by At

I want to use ContentAlignment.BottomRight but I have a problem with it.

I have a textbox with multiline. I am doing a calculator. Whatever I want to enter as a value and result, I want to see on BottomRight part (as it is in Windows calculator). In the properties part of my textbox, I set multiline=true

textbox.TextAlign = ContentAlignment.BottomRight; Gives the following error:

Cannot implicitly convert type 'System.Drawing.ContentAlignment' to 'System.Windows.Forms.HorizontalAlignment'. An explicit conversion exists (are you missing a cast?)

but textbox.TextAlign = HorizontalAlignment.Right; works.But in this case there is no BottomRight option, only Left, Center, Right.

I have included the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
1

There are 1 answers

2
Nathan M. On

Text box does not support vertical alignments. It only supports horizontal alignments, which is why there is only a Left, Center, and Right option.

You might consider researching a RichTextBox, but I have not been able to find any alignment properties in code, despite what I have found on the RichTextBox page on MSDN. (I am inclined to say that I am wrong instead of Microsoftm, so keep researching.)

Something else you might consider is using a PictureBox or Label if you are only displaying text. See a discussion on this topic on the MSDN forums.

One last thing to consider is looking into controls in which you can put html. This seems overkill to me, but you can find someone's question about it at this StackOverflow question.