Solved

Centered Text

Posted on 2006-11-27
5
250 Views
Last Modified: 2010-04-23
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
Comment
Question by:huji
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 18022120
The best thing to do here is set the width of the label to the width of the panel.
then, centre the text.
0
 
LVL 14

Author Comment

by:huji
ID: 18022174
>> 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
 
LVL 14

Author Comment

by:huji
ID: 18022191
Actually, even this didn't help:

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

0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18022266
You can set it via code in your panel.resize event.

With Label
  .Left=0
  .Top = ??
  .Width = parent.width
  .Height = ??
End with
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 300 total points
ID: 18022421
or you could do it like so :

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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question