SnapLines not honored during resize.

R

ravi.s.desai

I have a custom control that contains a textbox. It has two
properties, Name (string), and UoM (string). The name should show on
the control before the textbox, and the UoM should show on the control
after the textbox. The usercontrol sets its MinimumSize based on a
fixed minimum size of the textbox, the measured length of the name
string, and the measured length of the UoM string (both using
Graphics.MeasureString with the current font).

OnLayout positions and sizes the text box so that it is that maximum
possible size where the name string and the unit of measure string are
still visible (they are drawn on the control surface during OnPaint).

I have defined custom snap lines on the designer for the control so
that the user can easily align the controls in such a way that the
text boxes are all lined up. So my Left snap line is at the end of
the name string (based on the MeasureString length) and my Right snap
line is at the beginning of the UoM string (again based on the
MeasureString length). To keep things simple, defined Top and Bottom
snap lines as well, but no others, only those 4 snap lines exist.
This meqns that the left edge and the right edge are not snap lines.

Now if I drop two different instances of this usercontrol onto a form,
and give them different names and UoM strings, it is very easy to drag
one on top of the other and to align the left edge of the text boxes
using the snap lines. However, I would also like to align the right
edge of the text boxes by resizing one of the controls. This is where
the problem comes in. During resize, a snap line appears when the
right edge of the control (which is not a snap line at all) comes in
proximity with the right-snap line associated with the beginning of
the UoM string of the other control. The snap lines defined for the
control I am resizing never appear at all.

In other words, during resize, snap lines only appear for the right
edge of the control, and it will always try to snap to the right snap
line of a nearby control. Which is not the behavior I want at all.
Can anyone shed some light here?
 
R

ravi.s.desai

I have a custom control that contains a textbox. It has two
properties, Name (string), and UoM (string). The name should show on
the control before the textbox, and the UoM should show on the control
after the textbox. The usercontrol sets its MinimumSize based on a
fixed minimum size of the textbox, the measured length of the name
string, and the measured length of the UoM string (both using
Graphics.MeasureString with the current font).

OnLayout positions and sizes the text box so that it is that maximum
possible size where the name string and the unit of measure string are
still visible (they are drawn on the control surface during OnPaint).

I have defined custom snap lines on the designer for the control so
that the user can easily align the controls in such a way that the
text boxes are all lined up. So my Left snap line is at the end of
the name string (based on the MeasureString length) and my Right snap
line is at the beginning of the UoM string (again based on the
MeasureString length). To keep things simple, defined Top and Bottom
snap lines as well, but no others, only those 4 snap lines exist.
This meqns that the left edge and the right edge are not snap lines.

Now if I drop two different instances of this usercontrol onto a form,
and give them different names and UoM strings, it is very easy to drag
one on top of the other and to align the left edge of the text boxes
using the snap lines. However, I would also like to align the right
edge of the text boxes by resizing one of the controls. This is where
the problem comes in. During resize, a snap line appears when the
right edge of the control (which is not a snap line at all) comes in
proximity with the right-snap line associated with the beginning of
the UoM string of the other control. The snap lines defined for the
control I am resizing never appear at all.

In other words, during resize, snap lines only appear for the right
edge of the control, and it will always try to snap to the right snap
line of a nearby control. Which is not the behavior I want at all.
Can anyone shed some light here?

Actually, to simplify the above, it appears that when you are resizing
a control, all snaplines defined in the designer are completely
ignored, and the designer simply creates a snap-line for the edge of
the control that you are dragging, and uses that exclusively. Is this
by design? It certainly seems to limit the value of snaplines for
layout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top