ekolis
ekolis

Reputation: 6786

The wider I make my user control, the more gets cut off on the right

I have a user control containing 2 child controls:

I expect the picture box to stay attached to the right side of the control, which it does in the designer. However, when I actually run my program, the picture box seems to float off the right side of the control if I make the control wider than about 100 pixels, and at 150 pixels, the picture box (which is 20x20) is completely invisible!

I don't have any code adjusting the anchor style of the picture box at runtime, so how can this be happening and how can I fix it?

Upvotes: 1

Views: 1432

Answers (4)

jockewe
jockewe

Reputation: 21

I solved this problem by setting the AutoScaleMode property in the parent control to None.

Upvotes: 2

ekolis
ekolis

Reputation: 6786

Actually, using Dock instead of Anchor seems to have solved my problem! I set the picture box to dock right, and the label to dock fill, and now it seems to look right!

Upvotes: 1

Mikhail Tregubov
Mikhail Tregubov

Reputation: 68

I think just using Anchors instead of setting Docks may help:

If you intend PictureBox just to be attached to the right side of control - use Anchor property set to Right | Top (but it can overlay label on the left in case, when control width will be to small)

If you intend to stretch PictureBox when control is resized vertically then set Anchor = Right | Top | Bottom.

If you want PictureBox to stretch vertically and horizontally when container control resized set all Anchors (in that case label won't be overlayed by PictureBox)

Labels Anchor is better to set to just Left | Top, because anchoring it to Left | Right, may lately, in case with different TextAlign values, be causing shifts of text across the control when resizing

Upvotes: 0

Guillermo Gutiérrez
Guillermo Gutiérrez

Reputation: 17799

May I suggest you to use the Anchor property, instead of the Dock property, with the same values.

Upvotes: 0

Related Questions