Control alignment issues in custom UserControl

R

rrossney

I'm building a UserControl that contains a number of other controls
that it creates and lays out at runtime. I've been messing about
quite a bit with containers and docking and anchoring, and I can't get
it to do exactly what I want it to do. What I want it to do seems
like it would be a pretty common use case, but no amount of searching
has found what I'm looking for. Perhaps someone here can give me a
pointer.

My control takes a list of names and values and lays out a linear
sequence of corresponding Label and TextBox controls. The best
version of it that I've come up with to date positions the controls
from left to right by docking them inside a Panel.

That controls horizontal layout. But the vertical positioning of the
controls stinks: the docked controls are laid out with their tops
aligned to each other, which looks unfortunate at small font sizes and
ugly as sin at large ones.

What I'd ideally like to do is lay out the labels so that their bottom
edge is lined up with the TextBoxes' horizontal snapline. But the
snapline doesn't seem to be accessible at runtime. So my first
question is: am I mistaken? Is there a way of getting a control's
snapline at runtime?

Just to make matters more complicated, I'd like to make my control
incorporate a FlowLayoutPanel, so that if there are too many Label/
TextBox pairs to lay out in the horizontal space available, they'll
wrap without my having to do much programming. To make *this* work, I
think that I need to set things up so that all of the controls I'm
laying out have the same height, which means calculating margins and/
or padding based on the Font that the controls are using.

I can, eventually, figure all of this out, I'm sure. But someone has
to have already solved this problem. I'd appreciate any pointers that
anyone can give me to prior work on this subject.

Thanks in advance,

Bob Rossney
(e-mail address removed)
 
G

Guest

Potentially you could make a control at design time which is a label-textbox
pair and set the lable and the usercontrol to autosize. You may need to put
in some code to keep moving the text box to be immediatly after the label (or
you could use panels and docking but they would consume handles quickly).
Then add these to the form and runtime.
Someone somewhere has to code the logic you want, it would be great if MS
could guess all our needs but sometimes, what you see as everyday, they would
have designed forms differently and therefore wouldnt encounter.
 
R

rrossney

Potentially you could make a control at design time which is a label-textbox
pair and set the lable and theusercontrolto autosize. You may need to put
in some code to keep moving the text box to be immediatly after the label (or
you could use panels and docking but they would consume handles quickly).
Then add these to the form and runtime.

I don't think this solves the problem I'm having, which pertains to
the vertical alignment of the controls. Positioning the controls so
that they align on the snapline at design time is fine, so long as the
user never changes the font size. But the position of the snapline
depends on the font size. If the font size changes at run time, the
snapline, which is a design-time parameter, isn't available.

This is why I'm sure someone has solved this problem: MSFT is urging
us to make dynamically UIs, and part of that dynamism is giving the
users control over the UI's font size. It seems unlikely that they'd
create a feature that broke as soon as people did what they were
suggesting they do.

Bob Rossney
(e-mail address removed)
 

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