Example #1
0
        public OptionPageWinForms(int aWidth, IOptionPage aOptionPage)
        {
            iLabels             = new List <Label>();
            iOptions            = new List <IOptionWinForms>();
            iOptionPage         = aOptionPage;
            iControl            = new ContainerControl();
            iControl.AutoScroll = true;

            // set the width of the page control before any children are added
            iControl.Width = aWidth;
            iControl.Dock  = DockStyle.Fill;

            for (int i = 0; i < iOptionPage.Options.Count; i++)
            {
                Option option = iOptionPage.Options[i];

                // create the option control
                IOptionWinForms optionWinform = null;

                if (option is OptionEnum || option is OptionNetworkInterface)
                {
                    optionWinform = new OptionWinFormsEnumerated(option);
                }
                else if (option is OptionBool)
                {
                    optionWinform = new OptionWinFormsBool(option);
                }
                else if (option is OptionFilePath ||
                         option is OptionFolderPath ||
                         option is OptionColor ||
                         option is OptionListFolderPath)
                {
                    throw new NotImplementedException();
                }

                if (optionWinform != null)
                {
                    // create the label control
                    Label labelControl = new Label();
                    labelControl.Text      = option.Name + ":";
                    labelControl.TextAlign = ContentAlignment.TopLeft;

                    iControl.Controls.Add(labelControl);
                    iControl.Controls.Add(optionWinform.Control);

                    iLabels.Add(labelControl);
                    iOptions.Add(optionWinform);
                }
            }

            // now update the layout of all controls
            UpdateLayout();
        }
Example #2
0
        public OptionPageWinForms(int aWidth, IOptionPage aOptionPage, Control aHelpTextControl)
        {
            iOptions            = new List <IOptionWinForms>();
            iOptionPage         = aOptionPage;
            iControl            = new ContainerControl();
            iControl.AutoScroll = true;
            iHelpTextControl    = aHelpTextControl;

            // set the width of the page control before any children are added
            iControl.Width = aWidth;

            int labelWidth  = aWidth / 2;
            int optionWidth = aWidth - labelWidth;
            int currentY    = 0;

            for (int i = 0; i < iOptionPage.Options.Count; i++)
            {
                Option option = iOptionPage.Options[i];

                // create the label for the option
                Label labelControl = new Label();
                labelControl.AutoSize  = false;
                labelControl.Text      = option.Name;
                labelControl.TextAlign = ContentAlignment.MiddleLeft;

                // create the option control
                IOptionWinForms optionWinform = null;

                if (option is OptionEnum || option is OptionNetworkInterface || option is OptionBoolEnum)
                {
                    optionWinform = new OptionWinFormsEnumerated(option);
                }
                else if (option is OptionFilePath)
                {
                    optionWinform = new OptionWinFormsFilePath(option, optionWidth);
                }
                else if (option is OptionFolderPath)
                {
                    optionWinform = new OptionWinFormsFolderPath(option, optionWidth);
                }
                else if (option is OptionFolderName)
                {
                    optionWinform = new OptionWinFormsFolderName(option, optionWidth);
                }
                else if (option is OptionUri)
                {
                    optionWinform = new OptionWinFormsUri(option, optionWidth);
                }
                else if (option is OptionBool)
                {
                    optionWinform = new OptionWinFormsBool(option);
                }
                else if (option is OptionColor)
                {
                    optionWinform = new OptionWinFormsARGB(option);
                }
                else if (option is OptionListFolderPath)
                {
                    optionWinform = new OptionWinFormsListFolderPath(option, optionWidth);
                }
                else if (option is OptionInt)
                {
                    optionWinform = new OptionWinFormsInt(option);
                }
                else if (option is OptionUint)
                {
                    optionWinform = new OptionWinFormsUint(option);
                }
                else if (option is OptionNumber)
                {
                    optionWinform = new OptionWinFormsNumber(option);
                }
                else if (option is OptionString)
                {
                    optionWinform = new OptionWinFormsString(option);
                }

                // calculate positioning of the controls
                if (optionWinform != null)
                {
                    iOptions.Add(optionWinform);
                    Control optionControl = optionWinform.Control;

                    labelControl.Location = new Point(0, currentY);
                    labelControl.Anchor   = AnchorStyles.Left | AnchorStyles.Top;
                    labelControl.TabStop  = false;
                    labelControl.Width    = labelWidth;
                    labelControl.Height   = optionControl.Height;

                    optionControl.Location = new Point(labelWidth, currentY);
                    optionControl.Width    = optionWidth;
                    optionControl.Anchor   = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    optionControl.TabStop  = true;
                    optionControl.TabIndex = i;

                    if (aHelpTextControl != null)
                    {
                        labelControl.Tag     = optionControl;
                        labelControl.Click  += SelectOptionLabel;
                        optionControl.Tag    = labelControl;
                        optionControl.Name   = option.Description;
                        optionControl.Enter += SelectOption;
                        optionControl.Leave += DeselectOption;
                    }

                    iControl.Controls.Add(labelControl);
                    iControl.Controls.Add(optionControl);

                    currentY += optionControl.Height;
                }
            }
        }