Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Control alignment issues in custom UserControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rrossney@gmail.com - 05 Feb 2007 00:05 GMT
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
rrossney@gmail.com
Ciaran O''Donnell - 05 Feb 2007 10:46 GMT
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.

Signature

Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com

> 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
[quoted text clipped - 36 lines]
> Bob Rossney
> rrossney@gmail.com
rrossney@gmail.com - 06 Feb 2007 17:16 GMT
On Feb 5, 2:46 am, Ciaran O''Donnell
<CiaranODonn...@discussions.microsoft.com> wrote:
> 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
rbr@well.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.