コード例 #1
0
        public RadioButton(ControlBase parent)
            : base(parent)
        {
            Control.RadioButtonGroup rbg = new Control.RadioButtonGroup(this, "Sample radio group");
            rbg.SetPosition(10, 10);

            rbg.AddOption("Option 1");
            rbg.AddOption("Option 2");
            rbg.AddOption("Option 3");
            rbg.AddOption("\u0627\u0644\u0622\u0646 \u0644\u062D\u0636\u0648\u0631");
            //rbg.SizeToContents(); // it's auto

            rbg.SelectionChanged += OnChange;

            Control.LabeledRadioButton rb1 = new LabeledRadioButton(this);
            rb1.Text = "Option 1";
            rb1.SetPosition(300, 10);

            Control.LabeledRadioButton rb2 = new LabeledRadioButton(this);
            rb2.Text = "Option 2222222222222222222222222222222222";
            rb2.SetPosition(300, 30);

            Control.LabeledRadioButton rb3 = new LabeledRadioButton(this);
            rb3.Text = "\u0627\u0644\u0622\u0646 \u0644\u062D\u0636\u0648\u0631";
            rb3.SetPosition(300, 50);

            //this.DrawDebugOutlines = true;
        }
コード例 #2
0
 /// <summary>
 /// Adds an option.
 /// </summary>
 /// <param name="lrb">Radio button.</param>
 public virtual void AddOption(LabeledRadioButton lrb)
 {
     lrb.Checked += OnRadioClicked;
     lrb.Margin   = new Margin(0, 0, 0, 1);
     lrb.KeyboardInputEnabled = false;
     lrb.IsTabable            = true;
 }
コード例 #3
0
        /// <summary>
        /// Adds a new option.
        /// </summary>
        /// <param name="text">Option text.</param>
        /// <param name="optionName">Internal name.</param>
        /// <returns>Newly created control.</returns>
        public virtual LabeledRadioButton AddOption(string text, string optionName)
        {
            LabeledRadioButton lrb = new LabeledRadioButton(this);
            lrb.Name = optionName;
            lrb.Text = text;
            lrb.RadioButton.Checked += OnRadioClicked;
            lrb.Dock = Pos.Top;
            lrb.Margin = new Margin(0, 0, 0, 1); // 1 bottom
            lrb.KeyboardInputEnabled = false; // todo: true?
            lrb.IsTabable = true;

            Invalidate();
            return lrb;
        }
コード例 #4
0
 public EnumRadioButtonGroup(ControlBase parent) : base(parent)
 {
     if (!typeof(T).IsEnum)
     {
         throw new Exception("T must be an enumerated type!");
     }
     this.Text = typeof(T).Name;
     for (int i = 0; i < Enum.GetValues(typeof(T)).Length; i++)
     {
         string             name = Enum.GetNames(typeof(T))[i];
         LabeledRadioButton lrb  = this.AddOption(name);
         lrb.UserData = Enum.GetValues(typeof(T)).GetValue(i);
     }
 }
コード例 #5
0
        /// <summary>
        /// Adds a new option.
        /// </summary>
        /// <param name="text">Option text.</param>
        /// <param name="optionName">Internal name.</param>
        /// <param name="userData">User data.</param>
        /// <returns>Newly created control.</returns>
        public virtual LabeledRadioButton AddOption(string text, string optionName = null, object userData = null)
        {
            LabeledRadioButton lrb = new LabeledRadioButton(this);

            lrb.Name                 = optionName;
            lrb.UserData             = userData;
            lrb.Text                 = text;
            lrb.Checked             += OnRadioClicked;
            lrb.Margin               = new Margin(0, 0, 0, 1);
            lrb.KeyboardInputEnabled = false;
            lrb.IsTabable            = true;

            return(lrb);
        }
コード例 #6
0
        /// <summary>
        /// Adds a new option.
        /// </summary>
        /// <param name="text">Option text.</param>
        /// <param name="optionName">Internal name.</param>
        /// <returns>Newly created control.</returns>
        public virtual LabeledRadioButton AddOption(string text, string optionName)
        {
            LabeledRadioButton lrb = new LabeledRadioButton(this);

            lrb.Name = optionName;
            lrb.Text = text;
            lrb.RadioButton.Checked += OnRadioClicked;
            lrb.Dock   = Pos.Top;
            lrb.Margin = new Margin(0, 0, 0, 1); // 1 bottom
            lrb.KeyboardInputEnabled = false;    // todo: true?
            lrb.IsTabable            = true;

            Invalidate();
            return(lrb);
        }
コード例 #7
0
        /// <summary>
        /// Handler for the option change.
        /// </summary>
        /// <param name="fromPanel">Event source.</param>
        protected virtual void OnRadioClicked(Base fromPanel, EventArgs args)
        {
            RadioButton @checked = fromPanel as RadioButton;

            foreach (LabeledRadioButton rb in Children.OfType <LabeledRadioButton>()) // todo: optimize
            {
                if (rb.RadioButton == @checked)
                {
                    m_Selected = rb;
                }
                else
                {
                    rb.RadioButton.IsChecked = false;
                }
            }

            OnChanged(m_Selected);
        }
コード例 #8
0
        /// <summary>
        /// Handler for the option change.
        /// </summary>
        /// <param name="fromPanel">Event source.</param>
        protected virtual void OnRadioClicked(Base fromPanel, EventArgs args)
        {
            RadioButton @checked = fromPanel as RadioButton;
            foreach (LabeledRadioButton rb in Children.OfType<LabeledRadioButton>()) // todo: optimize
            {
                if (rb.RadioButton == @checked)
                    m_Selected = rb;
                else
                    rb.RadioButton.IsChecked = false;
            }

            OnChanged(m_Selected);
        }