PC Review


Reply
Thread Tools Rate Thread

Control alignment issues in custom UserControl

 
 
rrossney@gmail.com
Guest
Posts: n/a
 
      5th Feb 2007
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 Removed)

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=
Guest
Posts: n/a
 
      5th Feb 2007
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.




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


"(E-Mail Removed)" wrote:

> 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 Removed)
>
>

 
Reply With Quote
 
rrossney@gmail.com
Guest
Posts: n/a
 
      6th Feb 2007
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
(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Usercontrol or Custom control Matt Microsoft Dot NET Framework Forms 1 12th Sep 2005 10:23 AM
Custom Tab Control Alignment Problem lord soth via .NET 247 Microsoft Dot NET Framework Forms 0 18th Mar 2005 06:56 PM
Custom design-time control color issues... PeterB Microsoft Dot NET Compact Framework 3 21st Dec 2004 04:47 PM
Re: dataview issues in custom control William Ryan eMVP Microsoft ADO .NET 0 7th Jul 2004 03:15 PM
Custom Control Reference Issues Rob Microsoft Dot NET Compact Framework 0 18th May 2004 08:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 AM.