cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to center the caption of a static text?

leon_laikan
Participant
0 Kudos

Hi, everybody

I am developing an SDK add-on using VB.NET.

I don't use Screen Painter or any other visual tools. All dimensions are specified by coding.

For ex. This is how I code a Static Text

oItem = Form1.Items.Add("Static3", SAPbouiCOM.BoFormItemTypes.it_STATIC)

oItem.FontSize = 16

oItem.Left = 150

oItem.Top = 190

oItem.Width = 200

Static1 = oItem.Specific

Static1.Caption = "Transfer of Goods From"

Is there a way to center the Caption within the item width of 200 specified?

By default, the caption is left justified.

I think there is no direct way to achieve this.

But is there a workaround?

Any ideas are most welcome.

Thanks

Leon

Accepted Solutions (1)

Accepted Solutions (1)

former_member185682
Active Contributor
0 Kudos

Hi Leon,

For center the Caption in the Static Text, I believe that not exists a direct way to achieve this.

But the item has a member called RightJustified, maybe this can help you in a workaround.

Regards,

Diego

leon_laikan
Participant
0 Kudos

Hi,Diego

Thanks a lot for your reply.

Do you have any idea how I can use RightJustified in a workaround?

Best Regards,

Leon

former_member185682
Active Contributor
0 Kudos

Hi Leon,

I would go use something like this:

SAPbouiCOM.Item oItem = null;

SAPbouiCOM.StaticText oStatic = null;

oItem = oForm.Items.Add("stExample", SAPbouiCOM.BoFormItemTypes.it_STATIC);

oItem.Top = oForm.Items.Item("2").Top; //I set the top of my static text as the top of cancel button

oItem.Height = oForm.Items.Item("2").Height; //I set the height of my static text, equals the height of cancel button

oItem.Left = oForm.Items.Item("2").Left + oForm.Items.Item("2").Width + 5; //I set the position of my static text beside the cancel button

oItem.Width = 260;

oItem.RightJustified = true;

The result:

The black area is my space in the form, and the red area is my static text area, that I define with width 260, and set the RightJustified for true..

leon_laikan
Participant
0 Kudos

Hi, Diego

Thanks a lot for your reply.

Sorry for not replying earlier - got a bad flu.

I shall try your suggestion as soon as possible.

Best Regards,

Leon

Answers (1)

Answers (1)

Former Member
0 Kudos

To achieve something "similar" to centering, all that you have to do is to make sure that the font size of your text and the width of your StaticText field correlate with each other in such a way that the text goes all the way to the end of the StaticText field - no longer, and no shorter. Then you simply place the StaticText field EXACTLY where you want it to go. Then "centering" will not be necessary.

It will take some trial and error to get exactly the right numbers you need for the right effect, but you can do it. It's just not nicely automatic, it will be a manual process.

To explain another way, make sure that your Label field is exactly as wide as the text that you wish to display without any extra whitespace, then put the text exactly where you want it to appear. It's as simple as that.

leon_laikan
Participant
0 Kudos

Hi, Wesley

Thanks a lot for your reply.

I will try your tip.

Best Regards,

Leon