Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Text align in text box 1

Status
Not open for further replies.

Katy44

Technical User
Dec 12, 2003
723
GB
I have a form and I want to loop through all the textboxes on my form and align the text to the center.
This is the code I have used:

for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls is TextBox)
{
((TextBox)(this.Controls)).TextAlign =
HorizontalAlignment.Center;
}
}

A similar method has worked to assign a function to each textbox for onExit.
No problems are picked up on this, and the solution runs, but the text isn't aligned!
Any help would be appreciated.
 
Katy44,
I tried your code and it works as expected. Perhaps you have done something else that prevents the form or its controls from being repainted when you change the TextBoxes' alignment. I wouldn't know what would cause such behaviour, though. You might want to try to call this.Refresh() after the loop in your code to see if that helps with anything.

I'm aware of the fact that when the ResizeRedraw control style of a form is off, such form will not redraw its client area when resized. But, like I said, I'm not sure what would cause the text boxes' alignment not to change! Perhaps this.Refresh() will get you going.

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
Thank you! this.Refresh worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top