开发者

How to determine width of a windows forms controls whose width was increased because it is Anchored?

I currently have a Textbox on a Windows Forms, and I need to dynamically add a PictureBox box control at the right of the Textbox.

I create the PictureBox programmatically and I when setting the location of the PictureBox, i'm setting like this:

pBox.Location = new Point(tbControl.Location.X + ctrl.Width, ctrl.Location.Y);

So i'm setting the picture box to be located at the X location of the textbox PLUS the width of the textbox. However, since the textbox has an anchor property set to right, its width increase开发者_C百科s to fill the space between itself and the form border.

Problem is, that even though the textbox's width is visually bigger than the actual value of Textbox.Width. the Width property is not taking into account the extra width of being anchored.

I already tried properties like Textbox.Bounds.Width, Textbox.ClientSize.Width, Textbox.DisplayRectangle.Width, etc. with no luck. All of those properties return the original Width of the control without taking into account the resized width due to the Anchor property.

Does anyone know how I can determine the real size of the textbox? Thank you


The Width property always tracks the current width of a control, whether it is anchored or not. However, the TextBox is going to grow when you make the container larger and that will make it overlap the PictureBox. You have to anchor the PB to the right as well.


These should be returning the adjusted size. Either you are referring to the wrong textbox, or you are doing the query before the size has actually changed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜