Apply anchoring after resizing a control (1 Viewer)

dpm

Registered User.
Local time
Today, 07:23
Joined
Mar 20, 2009
Messages
22
Consider please a Form with two controls on it.


On the left is any control - say, a TextBox.
On the right is another TextBox.


LeftTextBox anchoring is Stretch Down.
RightTextBox anchoring is Stretch Down and Across.


I'd like to show/hide LeftTextBox, the effect being that the control is either "expanded" or "collapsed".


This requires that I move RightTextBox - by changing its .Left property, in effect, moving it to the left to occupy the space previously consumed by the now hidden LeftTextBox.



I am now left with doing something about the width of RightTextBox. I can calculate an appropriate width and apply it, but then the control doesn't behave very well when resizing the Form.


It seems to me that it would all work brilliantly if I could somehow simply re-apply the anchoring of RightTextBox, after moving it.


Do any of you have experience doing such things and have any tips?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:23
Joined
Feb 19, 2013
Messages
16,607
I can calculate an appropriate width and apply it, but then the control doesn't behave very well when resizing the Form.
how are you calculating the width? what does 'doesn't behave very well' mean?

For years before stretch came along I have just used the move property or left/top/width/height individually without any problems
 

dpm

Registered User.
Local time
Today, 07:23
Joined
Mar 20, 2009
Messages
22
I calculate a width using the Form's .InsideWidth property. It works just fine, so it's not really an issue.

The behavior is another matter. It would be quite a tedious read were I to fully detail the misbehavior. It will suffice to say that, after manually setting the control's width, the control apparently retains its initial width for purposes of anchoring. The control no longer resizes as expected when the parent Form is resized.

In any case, having studied the matter for a full day, I gave up. I don't think it is possible to get it to work and I doubt very much that such a scenario was tested by Microsoft to begin with.

Instead, I simply load one of two different subforms with controls arranged as desired. Indeed, I have also used the same properties for many years without trouble - except when Anchors that "stretch" are involved. I'd recommend not trying to mix the two.
 

Users who are viewing this thread

Top Bottom