Exemple #1
0
        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct a CheckBox instance from the given template.
        /// </summary>
        /// <param name="template"></param>
        public CheckBox(CheckBoxTemplate template)
            : base(template)
        {
            HasFrame = template.HasFrameBorder;

            if (Size.Height < 3 || Size.Width < 3)
            {
                HasFrame = false;
            }

            HilightWhenMouseOver = template.HilightWhenMouseOver;
            CanHaveKeyboardFocus = template.CanHaveKeyboardFocus;

            this.Label = template.Label;
            if (Label == null)
            {
                Label = "";
            }

            this.CheckOnLeft    = template.CheckOnLeft;
            this.LabelAlignment = template.LabelAlignment;
            this.VerticalAlign  = template.VerticalAlign;

            CalcMetrics(template);
        }
Exemple #2
0
        private void CalcMetrics(CheckBoxTemplate template)
        {
            Rect inner = this.LocalRect;

            if (template.HasFrameBorder && template.CalculateSize().Height >= 3)
            {
                inner = Rect.Inflate(inner, -1, -1);
            }

            int checkX;

            if (CheckOnLeft)
            {
                checkX    = inner.Left;
                labelRect = new Rect(inner.UpperLeft.Shift(1, 0),
                                     inner.LowerRight);
            }
            else
            {
                checkX    = inner.Right;
                labelRect = new Rect(inner.UpperLeft,
                                     inner.LowerRight.Shift(-1, 0));
            }

            if (labelRect.Size.Width < 1)
            {
                Label = "";
            }

            switch (VerticalAlign)
            {
            case VerticalAlignment.Bottom:
                checkPos = new Point(checkX, labelRect.Bottom);
                break;

            case VerticalAlignment.Center:
                checkPos = new Point(checkX, labelRect.Center.Y);
                break;

            case VerticalAlignment.Top:
                checkPos = new Point(checkX, labelRect.Top);
                break;
            }
        }
Exemple #3
0
        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Construct a CheckBox instance from the given template.
        /// </summary>
        /// <param name="template"></param>
        public CheckBox(CheckBoxTemplate template)
            : base(template)
        {
            HasFrame = template.HasFrameBorder;

            if (Size.Height < 3 || Size.Width < 3)
            {
                HasFrame = false;
            }

            HilightWhenMouseOver = template.HilightWhenMouseOver;
            CanHaveKeyboardFocus = template.CanHaveKeyboardFocus;

            this.Label = template.Label;
            if (Label == null)
                Label = "";

            this.CheckOnLeft = template.CheckOnLeft;
            this.LabelAlignment = template.LabelAlignment;
            this.VerticalAlign = template.VerticalAlign;

            CalcMetrics(template);
        }
Exemple #4
0
 public FancyCheck(CheckBoxTemplate template)
     : base(template)
 {
 }
Exemple #5
0
        protected override void OnSettingUp()
        {
            base.OnSettingUp();

            CheckBoxTemplate cb1 = new CheckBoxTemplate()
            {
                Label = " A Checkbox",
                UpperLeftPos = ViewRect.UpperLeft.Shift(1, 3),
            };
            AddControl(new CheckBox(cb1));

            CheckBoxTemplate cb2 = new CheckBoxTemplate()
            {
                Label = " Checkbox",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = true
            };
            cb2.AlignTo(LayoutDirection.South, cb1, 1);
            AddControl(new CheckBox(cb2));

            CheckBoxTemplate cb3 = new CheckBoxTemplate()
            {
                Label = "Checkbox",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = true,
                LabelAlignment = HorizontalAlignment.Right
            };
            cb3.AlignTo(LayoutDirection.South, cb2, 1);
            AddControl(new CheckBox(cb3));

            CheckBoxTemplate cb4 = new CheckBoxTemplate()
            {
                Label = "Checkbox",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = true,
                LabelAlignment = HorizontalAlignment.Center,
            };
            cb4.AlignTo(LayoutDirection.South, cb3, 1);
            AddControl(new CheckBox(cb4));

            CheckBoxTemplate cb5 = new CheckBoxTemplate()
            {
                Label = "Checkbox",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = false,
                LabelAlignment = HorizontalAlignment.Left,
                VerticalAlign = VerticalAlignment.Center,
                AutoSizeOverride = new Size(14,3),
                HasFrameBorder = false,
            };
            cb5.AlignTo(LayoutDirection.East, cb2, 1);
            AddControl(new CheckBox(cb5));

            CheckBoxTemplate cb6 = new CheckBoxTemplate()
            {
                Label = "Checkbox ",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = false,
                LabelAlignment = HorizontalAlignment.Right,
                VerticalAlign = VerticalAlignment.Center,
                AutoSizeOverride = new Size(14, 3),
                HasFrameBorder = false,
            };
            cb6.AlignTo(LayoutDirection.South, cb5, 1);
            AddControl(new CheckBox(cb6));

            CheckBoxTemplate cb7 = new CheckBoxTemplate()
            {
                Label = Color.CYAN.DoForegroundCode() + "C" +
                    Color.RED.DoForegroundCode() + "o"+
                    Color.BLUE.DoForegroundCode() + "l"+
                    Color.BRASS.DoForegroundCode() + "o"+
                    Color.DARK_LIME.DoForegroundCode() + "r"+
                    Color.LIGHT_MAGENTA.DoForegroundCode() + "s" +
                    Color.StopColorCode + "!! ",
                CheckOnLeft = false,
                LabelAlignment = HorizontalAlignment.Center,
                HasFrameBorder = false,
            };
            cb7.AlignTo(LayoutDirection.South, cb6, 1);
            AddControl(new CheckBox(cb7));

            CheckBoxTemplate cb8 = new CheckBoxTemplate()
            {
                Label = "Custom",
                MinimumWidth = cb1.CalculateSize().Width,
                CheckOnLeft = false,
                LabelAlignment = HorizontalAlignment.Center,
            };
            cb8.AlignTo(LayoutDirection.North, cb5, 1);
            AddControl(new FancyCheck(cb8));

            ListBoxTemplate lb1 = new ListBoxTemplate()
            {
                Title = "A List Box",
                Items = new System.Collections.Generic.List<ListItemData>()
                {
                    new ListItemData("Item 1","Item 1 Tooltip"),
                    new ListItemData("Item 2","Item 2 Tooltip"),
                    new ListItemData("Item 3","Item 3 Tooltip"),
                    new ListItemData("Item 4","Item 4 Tooltip")
                },
            };
            lb1.AlignTo(LayoutDirection.South, cb4, 2);
            AddControl(new ListBox(lb1));

            ListBoxTemplate lb2 = new ListBoxTemplate()
            {
                Title = "A List Box",
                TitleAlignment = HorizontalAlignment.Right,
                LabelAlignment = HorizontalAlignment.Center,
                MinimumListBoxWidth = 20,
                Items = new System.Collections.Generic.List<ListItemData>()
                {
                    new ListItemData("Item 1","Item 1 Tooltip"),
                    new ListItemData("Item 2","Item 2 Tooltip"),
                    new ListItemData("Item 3","Item 3 Tooltip"),
                    new ListItemData("Item 4","Item 4 Tooltip")
                }
            };
            lb2.AlignTo(LayoutDirection.East, lb1, 2);
            AddControl(new ListBox(lb2));

            TextEntryTemplate t1 = new TextEntryTemplate()
            {
                Label = "Text Entry (Hit Enter to keep): ",
                MaximumCharacters = 6
            };
            t1.AlignTo(LayoutDirection.East, cb8, 2);
            AddControl(new TextEntry(t1));

            TextEntryTemplate t2 = new TextEntryTemplate()
            {
                Label = "Symbols Only: ",
                Validation = TextEntryValidations.Symbols,
                MaximumCharacters = 25
            };
            t2.AlignTo(LayoutDirection.South, t1, 2);
            AddControl(new TextEntry(t2));

            TextEntryTemplate t3 = new TextEntryTemplate()
            {
                Label = "Numbers & Symbols: ",
                Validation = TextEntryValidations.Numbers | TextEntryValidations.Symbols,
                MaximumCharacters = 20
            };
            t3.AlignTo(LayoutDirection.South, t2, 2);
            AddControl(new TextEntry(t3));

            TextEntryTemplate t4 = new TextEntryTemplate()
            {
                Label = "Don't need to hit Enter: ",
                MaximumCharacters = 4,
                CommitOnLostFocus = true,
            };
            t4.AlignTo(LayoutDirection.South, t3, 2);
            t4.UpperLeftPos = t4.UpperLeftPos.Shift(4, 0);
            AddControl(new TextEntry(t4));

            TextEntryTemplate t5 = new TextEntryTemplate()
            {
                Label = "Replace Text: ",
                MaximumCharacters = 11,
                CommitOnLostFocus = true,
                ReplaceOnFirstKey = true,
                StartingField = "Replace me",
                HasFrameBorder = false
            };
            t5.AlignTo(LayoutDirection.South, t4, 2);
            AddControl(new TextEntry(t5));

            ButtonTemplate mb1 = new ButtonTemplate()
            {
                Label = "Right Click for Menu"
            };
            mb1.AlignTo(LayoutDirection.South, lb2,3);
            AddControl(new MenuButton(mb1));

            RadioGroupTemplate rg1 = new RadioGroupTemplate()
            {
                Items = new System.Collections.Generic.List<RadioItemData>()
                {
                    new RadioItemData("Radio One","Tooltip for radio 1"),
                    new RadioItemData("Radio Two","Tooltip for radio 2"),
                    new RadioItemData("Radio Three","Tooltip for radio 3")
                },
            };
            rg1.AlignTo(LayoutDirection.South, t5, 2);
            AddControl(new RadioGroup(rg1));

            RadioGroupTemplate rg2 = new RadioGroupTemplate()
            {
                Items = new System.Collections.Generic.List<RadioItemData>()
                {
                    new RadioItemData("Radio One","Tooltip for radio 1"),
                    new RadioItemData("Radio Two","Tooltip for radio 2"),
                    new RadioItemData("Radio Three","Tooltip for radio 3")
                },
                HasFrameBorder = false,
                RadioOnLeft = false
            };
            rg2.AlignTo(LayoutDirection.South, rg1, 1);
            AddControl(new RadioGroup(rg2));

            PageInfo.AddText("This page shows a selection of Checkbox, TextEntry, ListBox, and RadioGroup controls." +
                "\n\nCheckbox controls are similar to buttons, except that there state (IsChecked) is persistant, and" +
                " this state is, by default, shown by a check box graphic." +
                "\n\nTextEntry controls allow user input.  Various behaviors of validation and committing the input are available." +
                "\n\nListBox controls are basically a list of clickable buttons with persistant state - one item is always the currently selected." +
                "\n\nMenu controls are similar to ListBox, except they automatically close if an item is selected or the mouse pointer leaves the area." +
                "\n\nRadioGroups are the same as ListBoxes, except the currently selected item is displayed differently.");
        }
Exemple #6
0
        private void CalcMetrics(CheckBoxTemplate template)
        {
            Rect inner = this.LocalRect;

            if (template.HasFrameBorder && template.CalculateSize().Height >= 3)
            {
                inner = Rect.Inflate(inner, -1, -1);
            }

            int checkX;

            if (CheckOnLeft)
            {
                checkX = inner.Left;
                labelRect = new Rect(inner.UpperLeft.Shift(1, 0),
                    inner.LowerRight);
            }
            else
            {
                checkX = inner.Right;
                labelRect = new Rect(inner.UpperLeft,
                    inner.LowerRight.Shift(-1, 0));
            }

            if (labelRect.Size.Width < 1)
            {
                Label = "";
            }

            switch (VerticalAlign)
            {
                case VerticalAlignment.Bottom:
                    checkPos = new Point(checkX, labelRect.Bottom);
                    break;

                case VerticalAlignment.Center:
                    checkPos = new Point(checkX, labelRect.Center.Y);
                    break;

                case VerticalAlignment.Top:
                    checkPos = new Point(checkX, labelRect.Top);
                    break;
            }
        }