コード例 #1
0
        protected void button_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            strButtonClickedName = button.Name;

            // identify which button was clicked and perform necessary actions
            foreach (ControlEntity item in _ListControlEntity)
            {
                switch (item.ControlType)
                {
                case ControlType.Button:
                    if (item.ID == strButtonClickedName)
                    {
                        item.ButtonPressed = true;
                    }
                    else
                    {
                        item.ButtonPressed = false;
                    }
                    break;

                case ControlType.TextBox:
                    TextBox myTextBox = new TextBox();
                    myTextBox = (TextBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Text = myTextBox.Text;
                    break;

                case ControlType.PasswordBox:
                    PasswordBox myPasswordBox = new PasswordBox();
                    myPasswordBox = (PasswordBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Text     = myPasswordBox.Password;
                    break;

                case ControlType.ComboBox:
                    ComboBox myComboBox = new ComboBox();
                    myComboBox = (ComboBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    if (myComboBox.SelectedIndex > -1)
                    {
                        item.SelectedValue = myComboBox.SelectedValue.ToString();
                        ComboBoxPair mySelectedPair = (ComboBoxPair)(myComboBox.SelectedItem);
                        item.SelectedKey = mySelectedPair._Key;
                    }
                    break;

                case ControlType.CheckBox:
                    CheckBox myCheckBox = new CheckBox();
                    myCheckBox   = (CheckBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Checked = myCheckBox.IsChecked ?? false;
                    break;

                default:
                    break;
                }
            }

            this.Close();
        }
コード例 #2
0
        public void funcUpdateCombobox1(string strNewHostName, object sender)
        {
            List <ComboBoxPair> alHosts    = ((ComboBox)sender).ItemsSource.Cast <ComboBoxPair>().ToList();
            List <ComboBoxPair> alHostsNew = new List <ComboBoxPair>();
            ComboBoxPair        myCbp      = new ComboBoxPair(strNewHostName, strNewHostName);
            bool boolNewItem = false;

            alHostsNew.Add(myCbp);

            foreach (ComboBoxPair item in alHosts)
            {
                if (strNewHostName != item._Key)
                {
                    boolNewItem = true;
                    alHostsNew.Add(item);
                }
            }
            if (alHostsNew.Count > 14)
            {
                for (int i = alHostsNew.Count - 1; i > 0; i--)
                {
                    if (alHostsNew[i]._Key.Trim() != "--Select Item ---")
                    {
                        alHostsNew.RemoveAt(i);
                        break;
                    }
                }
            }

            string fileName = ((ComboBox)sender).Name + ".txt";

            Methods myActions              = new Methods();
            string  strScriptName          = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
            string  strApplicationBinDebug = System.Windows.Forms.Application.StartupPath;
            string  myNewProjectSourcePath = strApplicationBinDebug.Replace("\\bin\\Debug", "");
            string  settingsDirectory      = GetAppDirectoryForScript(myActions.ConvertFullFileNameToScriptPath(myNewProjectSourcePath));

            string settingsPath = System.IO.Path.Combine(settingsDirectory, fileName);

            using (StreamWriter objSWFile = File.CreateText(settingsPath)) {
                foreach (ComboBoxPair item in alHostsNew)
                {
                    if (item._Key != "")
                    {
                        objSWFile.WriteLine(item._Key + '^' + item._Value);
                    }
                }
                objSWFile.Close();
            }

            //  alHosts = alHostsNew;
            if (boolNewItem)
            {
                ((ComboBox)sender).ItemsSource = alHostsNew;
            }
        }
コード例 #3
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // ... Get the ComboBox.
            var comboBox = sender as ComboBox;

            // ... Set SelectedItem as Window Title.
            ComboBoxPair cbp = (ComboBoxPair)comboBox.SelectedItem;

            this.Title           = "Selected: " + cbp._Value;
            SelectedComboBoxPair = cbp;
        }
コード例 #4
0
        private void btnOkay_Click(object sender, RoutedEventArgs e)
        {
            //boolOkayPressed = true;
            foreach (ControlEntity item in _ListControlEntity)
            {
                switch (item.ControlType)
                {
                case ControlType.TextBox:
                    TextBox myTextBox = new TextBox();
                    myTextBox = (TextBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Text = myTextBox.Text;
                    break;

                case ControlType.PasswordBox:
                    PasswordBox myPasswordBox = new PasswordBox();
                    myPasswordBox = (PasswordBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Text     = myPasswordBox.Password;
                    break;

                case ControlType.ComboBox:
                    ComboBox myComboBox = new ComboBox();
                    myComboBox = (ComboBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    if (myComboBox.SelectedIndex > -1)
                    {
                        item.SelectedValue = myComboBox.SelectedValue.ToString();
                        ComboBoxPair mySelectedPair = (ComboBoxPair)(myComboBox.SelectedItem);
                        item.SelectedKey = mySelectedPair._Key;
                    }
                    break;

                case ControlType.CheckBox:
                    CheckBox myCheckBox = new CheckBox();
                    myCheckBox   = (CheckBox)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Checked = myCheckBox.IsChecked ?? false;
                    break;

                case ControlType.Image:
                    Image myImage = new Image();
                    myImage     = (Image)LogicalTreeHelper.FindLogicalNode(this, item.ID);
                    item.Source = myImage.Source;
                    break;

                default:
                    break;
                }
            }
            strButtonClickedName = "btnOkay";
            boolOkayPressed      = true;
            this.Close();
        }
コード例 #5
0
        public void funcUpdateCombobox1(string strNewHostName, object sender)
        {
            List <ComboBoxPair> alHosts    = ((ComboBox)sender).ItemsSource.Cast <ComboBoxPair>().ToList();
            List <ComboBoxPair> alHostsNew = new List <ComboBoxPair>();
            ComboBoxPair        myCbp      = new ComboBoxPair(strNewHostName, strNewHostName);
            bool boolNewItem = false;

            alHostsNew.Add(myCbp);

            foreach (ComboBoxPair item in alHosts)
            {
                if (strNewHostName != item._Key)
                {
                    boolNewItem = true;
                    alHostsNew.Add(item);
                }
            }
            if (alHostsNew.Count > 24)
            {
                for (int i = alHostsNew.Count - 1; i > 0; i--)
                {
                    if (alHostsNew[i]._Key.Trim() != "--Select Item ---")
                    {
                        alHostsNew.RemoveAt(i);
                        break;
                    }
                }
            }
            string strScriptName     = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
            string settingsDirectory = GetAppDirectoryForScript();
            string fileName          = ((ComboBox)sender).Name + ".txt";
            string settingsPath      = System.IO.Path.Combine(settingsDirectory, fileName);

            using (StreamWriter objSWFile = File.CreateText(settingsPath)) {
                foreach (ComboBoxPair item in alHostsNew)
                {
                    if (item._Key != "")
                    {
                        objSWFile.WriteLine(item._Key + '^' + item._Value);
                    }
                }
                objSWFile.Close();
            }

            //  alHosts = alHostsNew;
            if (boolNewItem)
            {
                ((ComboBox)sender).ItemsSource = alHostsNew;
            }
        }