When Removed the border style of the text box text not alligned
-
Tuesday, August 07, 2012 9:43 AM
Hi I have a textbox and i am setting the value in the text box. I have set the textbox border style to none in the runtime when i am setting the value. It is displaying as below mentinoed image
Here if we observe the text is not alligned properly with Label, The tex went up.
So my question is how can you make the allignment to be equal with the label. I tried to set txt.textalligment =horizontalAllignemt.Center it didnt work. So Suggest me how can i make the value of the texbox to be alligned with label.
All Replies
-
Wednesday, August 08, 2012 2:44 AMModerator
Hi Raju_hai,
If you have tried to change the border style at design time, you may find that the Size of the TextBox also changes. The TextAlign property only changes the horizontal alignment of the text.
So I think the workaroud is to set the Location of the TextBox. Something like this:
int h = textBox1.Size.Height; textBox1.BorderStyle = BorderStyle.None; int h2 = textBox1.Size.Height; textBox1.Location += new Size(0, (h - h2)/2);
If there are any concerns, please feel free to let me know.
Best regards,
Chester Hong
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Chester HongMicrosoft Contingent Staff, Moderator Monday, August 13, 2012 9:05 AM
- Unmarked As Answer by Chester HongMicrosoft Contingent Staff, Moderator Monday, August 13, 2012 10:53 AM
-
Monday, August 13, 2012 9:11 AM
Hi Chester Hong,
Sorry for the delay reply, I have tried the same but could not able to make the text allign with the label. So what i did was
textBox1.BorderStyle = BorderStyle.None;
textBox1.Margin = new System.Windows.Forms.Padding(0, 6, 0, 0);My problem got resolved.Thanks For your help.
- Marked As Answer by Chester HongMicrosoft Contingent Staff, Moderator Monday, August 13, 2012 10:53 AM
-
Monday, August 13, 2012 10:54 AMModerator
Hi Raju_Hai,
Thanks for sharing your answer.
Have a nice day.
Best regards,
Chester Hong
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


