コード例 #1
0
        /// <summary>
        /// Recursively searches for a given control id in the
        /// collection passed via the <paramref name="ctrlColl"/> parameter.
        /// </summary>
        ///
        /// <param name="ctrlColl">A Collection&lt;CommonFileDialogControl&gt;</param>
        /// <param name="id">An int containing the identifier of the control
        /// being searched for.</param>
        ///
        /// <returns>A DialogControl who's Id matches the value of the
        /// <paramref name="id"/> parameter.</returns>
        ///
        internal DialogControl GetSubControlbyId(IEnumerable <T> ctrlColl,
                                                 int id)
        {
            DialogControl foundControl  = null;
            int           iSubCtrlCount = 0;

            // if ctrlColl is null, it will throw in the foreach.
            if (ctrlColl == null)
            {
                return(null);
            }

            foreach (DialogControl control in ctrlColl)
            {
                // Match?
                if (control.Id == id)
                {
                    return(control);
                }

                // Search GroupBox child items
                if (control is CommonFileDialogGroupBox)
                {
                    CommonFileDialogGroupBox groupBox = control as CommonFileDialogGroupBox;

                    // recurse and search the GroupBox
                    iSubCtrlCount =
                        ((CommonFileDialogGroupBox)control).Items.Count;

                    if (iSubCtrlCount > 0)
                    {
                        foundControl = this.GetSubControlbyId(
                            groupBox.Items as IEnumerable <T>,
                            id);

                        // make sure something was actually found
                        if (foundControl != null)
                        {
                            return(foundControl);
                        }
                    }
                }
            }

            // Control id not found - likely an error, but the calling
            // function should ultimately decide.
            return(null);
        }
コード例 #2
0
ファイル: window1.xaml.cs プロジェクト: kyzmitch/Cip
        private void AddCustomControls(CommonFileDialog openDialog)
        {
            // Add a RadioButtonList
            CommonFileDialogRadioButtonList list = new CommonFileDialogRadioButtonList("Options");
            list.Items.Add(new CommonFileDialogRadioButtonListItem("Option A"));
            list.Items.Add(new CommonFileDialogRadioButtonListItem("Option B"));
            list.SelectedIndexChanged += RBLOptions_SelectedIndexChanged;
            list.SelectedIndex = 1;
            openDialog.Controls.Add(list);

            // Create a groupbox
            CommonFileDialogGroupBox groupBox = new CommonFileDialogGroupBox("Options");

            // Create and add two check boxes to this group
            CommonFileDialogCheckBox checkA = new CommonFileDialogCheckBox("Option A", true);
            CommonFileDialogCheckBox checkB = new CommonFileDialogCheckBox("Option B", true);
            checkA.CheckedChanged += ChkOptionA_CheckedChanged;
            checkB.CheckedChanged += ChkOptionB_CheckedChanged;
            groupBox.Items.Add(checkA);
            groupBox.Items.Add(checkB);

            // Create and add a separator to this group
            groupBox.Items.Add(new CommonFileDialogSeparator());

            // Create and add a button to this group
            CommonFileDialogButton btnCFDPushButton = new CommonFileDialogButton("Push Button");
            btnCFDPushButton.Click += PushButton_Click;
            groupBox.Items.Add(btnCFDPushButton);

            // Add groupbox to dialog
            openDialog.Controls.Add(groupBox);

            // Add a Menu
            CommonFileDialogMenu menu = new CommonFileDialogMenu("Sample Menu");
            CommonFileDialogMenuItem itemA = new CommonFileDialogMenuItem("Menu Item 1");
            CommonFileDialogMenuItem itemB = new CommonFileDialogMenuItem("Menu Item 2");
            itemA.Click += MenuOptionA_Click;
            itemB.Click += MenuOptionA_Click;
            menu.Items.Add(itemA);
            menu.Items.Add(itemB);
            openDialog.Controls.Add(menu);

            // Add a TextBox
            openDialog.Controls.Add(new CommonFileDialogLabel("Enter name"));
            openDialog.Controls.Add(new CommonFileDialogTextBox("textBox", Environment.UserName));

            // Add a ComboBox
            CommonFileDialogComboBox comboBox = new CommonFileDialogComboBox();
            comboBox.SelectedIndexChanged += ComboEncoding_SelectedIndexChanged;
            comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 1"));
            comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 2"));
            comboBox.SelectedIndex = 1;
            openDialog.Controls.Add(comboBox);
        }