Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Centered Text

Hello,
I have a panel, inside of which is a label. This label shows the name of a month (e.g. January, May, etc) This month name is changed based on the user input in other fields of the form. What I want to do: To make the label text appear "horizontally centered" in the panel. The default situation is the label's left position is fixed, so with the longer names (like January) the label will expand from the right side. I would like to expand equally from both sides.
Please advise
Huji
0
huji
Asked:
huji
  • 2
  • 2
1 Solution
 
Kinger247Commented:
The best thing to do here is set the width of the label to the width of the panel.
then, centre the text.
0
 
hujiAuthor Commented:
>> The best thing to do here is set the width of the label to the width of the panel.
I can't do that from the properties toolbox of the VS. Should I do this programatically?
0
 
hujiAuthor Commented:
Actually, even this didn't help:

        LabelMonth.Width = PanelMonth.Width
        LabelMonth.TextAlign = ContentAlignment.MiddleCenter

0
 
Kinger247Commented:
You can set it via code in your panel.resize event.

With Label
  .Left=0
  .Top = ??
  .Width = parent.width
  .Height = ??
End with
0
 
Mohamed ZedanCommented:
or you could do it like so :

LabelMonth.TextAlign = ContentAlignment.MiddleCenter
LabelMonth.left= (PanelMonth.width - LabelMonth.width) /2
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now