将控件定位在CheckBox的中间 [英] Positioning controls in the middle of a CheckBox

查看:181
本文介绍了将控件定位在CheckBox的中间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对我以前的问题的后续字体相关的控制定位这是试图解决这个问题背后的真正的问题,可能与我所问的不同。

问题陈述:我想要一个复选框,上面显示调整价格< X> < Y> ,其中< X> 是一个数字---可以用 NumericUpDown ---进行调整,而< Y> 可以是percent或美元,选择由 ComboBox 进行。这将是一条线。



并发症:我希望能够更改所有这些控件的字体(基本上设置它们到 System.Drawing.Fonts.MessageBoxFont ,这是在Windows XP / etc和Windows上的Tahoma 8 pt和Vista上的Segoe UI 9 pt),而不会搞乱我的布局,我现在的职位 - 属性 - 设置范例不起作用。

更一般地说,我想控制以独立于字体的方式进行动态布局,以便< X> NumericUpDown 紧贴在by和 code>符合< X> CheckBox 和右边的加载后的字符串



大家似乎错过的部分:全部嵌套在 CheckBox 中。因此,理想情况下,单击加载后字样应选中/取消选中复选框,然后在通过加载后调整价格周围绘制小高亮矩形。所以只要在结尾添加一个额外的 Label 不起作用,因为它不会切换 CheckBox ;同样,试图通过钩住这样一个标签的点击事件不会产生所需的高亮矩形。



解决方案在这一点上我想:


  1. 重新思考这个问题,不知何故,也许用一个丑陋的解决方案,比如两行文本:加载后调整已找到的价格( CheckBox NumericUpDown 组合框)。这是非常糟糕的,因为我的选项框是绝对充满了这种类型的选项(即在这个例子中的类型),所以它至少会在垂直大小加倍。


  2. 某种自定义控件? SplittableCheckBox


  3. 使用 TableLayout 控制? (可以肯定的是,在大家似乎都错过了的部分)。

  4. 放弃并返回MS Sans Serif,或者统一使用Tahoma,或者将Segoe用户界面与我的应用程序打包在一起,从而不尊重系统默认的字体。

  5. (新建,通过编辑)切换到WPF,如果有人能说服我,如果你有几个选项遵循这个布局的话,那么你可以使用这个布局来解决这个问题。 ,为什么不创建一个用户控件呢?用户控件将包含CheckBox,一个NumericUpDown,一个ComboBox和一个用于加载后的标签。你可以重写OnFontChanged来根据文本的渲染来调整控件的位置。给定的字体添加一个EventHandler的标签检查/取消选中复选框。

    至于有焦点矩形包围所有的控件,你应该能够给点击其内部控件之一时,用户控制焦点。


    THis is a followup to my previous question "Font-dependent control positioning." It's an attempt to solve the real problem behind that question, perhaps in ways different than the one I was asking about.

    Example of the problem statement: I want a checkbox that says "Adjust prices by <X> <Y> after loading," where <X> is a number---adjustable with a NumericUpDown---and <Y> is either "percent" or "dollars," with the choices being made by a ComboBox. This will be on a single line.

    The complication: I want to be able to change my fonts for all these controls (basically setting them to System.Drawing.Fonts.MessageBoxFont, which is Tahoma 8 pt on Windows XP/etc. and Segoe UI 9 pt on Vista), without messing up my layout, which with my current Position-property--setting paradigm does not work.

    More generally, I'd like the controls to be dynamically laid out in a font-independent way, so that the <X> NumericUpDown fits snugly into the space between "by " and the <Y> ComboBox, and similarly the <X> ComboBox fits in with respect to the <X> CheckBox and the string " after loading" to its right.

    The part everyone seems to miss: This is all nested within a CheckBox. So, ideally, clicking on the words "after loading" should check/uncheck the checkbox, and draw that little highlight rectangle around "Adjust prices by          after loading." So just slapping an extra Label on the end doesn't work, because then it doesn't toggle the CheckBox; similarly, trying to band-aid things by hooking up such a Label's Click event won't produce the desired highlight-rectangle.

    Solutions? At this point I'm thinking either:

    1. Rethink the problem, somehow, maybe with an ugly solution like two separate lines of text: "Adjust found prices after loading" (CheckBox), "Adjustment amount:" (NumericUpDown and ComboBox). This is really bad because my options box is absolutely full of options of this type (i.e. the type in the example), so it would at least double in vertical size.

    2. Some sort of custom control? SplittableCheckBox?

    3. Some kind of magic with a TableLayout control? (Pretty sure this fails at "the part everyone seems to miss.)

    4. Give up and either go back to MS Sans Serif, or use Tahoma uniformly, or package Segoe UI with my application, thus disrespecting the system default fonts.

    5. (New, via edit) Switch to WPF, if someone can convince me that it supports this scenario exactly.

    解决方案

    If you have several options that follow this layout, why not create a user control? The user control will contain the CheckBox, a NumericUpDown, a ComboBox and a label for the "after loading". You can override OnFontChanged to adjust the location of the controls based on the rendering of the text with the given font. Add an EventHandler to the Label to check/uncheck the CheckBox.

    As for having the focus rectangle surround all of the controls, you should be able to give the user control focus when one of its inner controls is clicked.

    这篇关于将控件定位在CheckBox的中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆