Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Center text vertically
 

Center text vertically

I have a user control in which I need to center a single line of text vertically. So far I have a textbox in the panel. The dock property is set to fill. However, the single line of text always displays at the top. How do I get it to be centered vertically?

When it is not set to multi-line, the text box only takes up one line of space. When it is set to multi-line, the text is displayed at the top of the box.

Edit:

As it turns out, it might be better to use a label. How would I get a label's text to be centered vertically and horizontally in a panel. When I set the Dock property to Fill, it doesn't change it size past what is needed to display the current text.

BioGeek  Tuesday, June 13, 2006 5:34 PM

Dock the label in a panel anduse TextAlign onthe label

label.TextAlign = ContentAlignment.MiddleCenter;

Hope this helps

Karthik Krishnaswami  Wednesday, June 14, 2006 3:52 AM
I have it docked with fill and middleCenter aligned. For a textbox, that center aligns the text horizontally but not vertically. For a label, it doesn't strech to fill the panel even though the dock is set.
BioGeek  Wednesday, June 14, 2006 11:41 AM

You can use google to search for other answers

Custom Search

More Threads

• How add a Column In DataGridView
• Clickable Image button in Windows forms
• Win32 and C# Window Styles. Why different ?
• Toolboxbitmap not visible, only in component tray
• About Creating Resource Dictionary for WPF themes
• Windows Control (Dont know the name)
• KEyboard Control
• TreeView custom property problem
• Windows Forms Designer would not accept event handler found in parent class
• Hide/Show Controls into the Panel