0

I got a few labels which show a entire week.
It's displaying the long date like this

LblCurrentDay.Text = Date.Now().ToString("D")
LblCurrentDay1.Text = Date.Now().AddDays(1).ToString("D")
LblCurrentDay2.Text = Date.Now().AddDays(2).ToString("D")
LblCurrentDay3.Text = Date.Now().AddDays(3).ToString("D")
LblCurrentDay4.Text = Date.Now().AddDays(4).ToString("D")
LblCurrentDay5.Text = Date.Now().AddDays(5).ToString("D")
LblCurrentDay6.Text = Date.Now().AddDays(6).ToString("D")

The labels are all inside each of their own small panel.
But since not all days day got the same length, sometimes it will be not centered.
Sometimes even partialy outside the panel and not visible.

So i would have to center them according to their size i guess.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Sevyt
0

To calculate the new position of the label, subtract half the width of the label from half the width of the panel as in

Label1.Location = New Point(Panel1.Width / 2 - Label1.Width / 2, Label1.Location.Y)

By default, labels are set to autosize so if you do this calculation when the text changes then the label should stay centered.

Edited by Reverend Jim

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.