Highlighted
Alex_Castro Respected Contributor.
Respected Contributor.
117 views

Align Text in WinForm

Jump to solution

I am trying to align the text in a text box to the right. I realize I can just set the text align property to the right on the form but I want to be able to do this in my code. The C# command is

textBox1.TextAlign = HorizontalAlignment.Right;

 

I have tried the following:

set txt-TOTAL-BALANCE::TextAlign to new type System.Windows.Forms.HorizontalAlignment

 

But this does not specify left, center or right. I have also tried

 

set txt-TOTAL-BALANCE::TextAlign to new type System.Windows.Forms.TextBox, TextAlign(Right)

 

But this code is incorrect and will not compile.

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: Align Text in WinForm

Jump to solution

The following works for me:

       set textBox1::TextAlign to type System.Windows.Forms.HorizontalAlignment::Right

If you add the following namespace directive to the top of the program:

      $set ilusing"System.Windows.Forms"

Then you can specify:

set textBox1::TextAlign to type HorizontalAlignment::Right

0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

Re: Align Text in WinForm

Jump to solution

The following works for me:

       set textBox1::TextAlign to type System.Windows.Forms.HorizontalAlignment::Right

If you add the following namespace directive to the top of the program:

      $set ilusing"System.Windows.Forms"

Then you can specify:

set textBox1::TextAlign to type HorizontalAlignment::Right

0 Likes
Alex_Castro Respected Contributor.
Respected Contributor.

Re: Align Text in WinForm

Jump to solution

I originally had

set textBox1::TextAlign to NEW type System.Windows.Forms.HorizontalAlignment::Right 

and I was getting an error because of the "NEW'

I took it out and set it like yours and it worked!

Thank you!

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Align Text in WinForm

Jump to solution

If you look at the MSDN docs for this here you will see that HorizontalAlignment is defined as an Enum and not a class. An enum is a value type which defines a set of constants so that you cannot instantiate it using the constructor New. 

Documentation of an Enum type can be found here.

Instances of classes are created using the New operator, which allocates memory for a new instance, invokes a constructor to initialize the instance, and returns a reference to the instance.

 

 

 

Austin1 Honored Contributor.
Honored Contributor.

Re: Align Text in WinForm

Jump to solution

@Alex_Castro If I understand your intent, this might also work:

set txt-TOTAL-BALANCE::RightToLeft to type System.Windows.Forms.RightToLeft::Yes

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.