コード例 #1
0
        /// <summary>
        /// Creates a default Path.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        private Panel CreateBrowseEntry(Position position, Path tag)
        {
            // TextBox
            TextBox txt = new TextBox();

            txt.TabIndex = position.NextTabIndex;
            txt.Name     = "pathTextBox" + position.TabIndex.ToString();
            txt.Width    = position.WidthColumnOne - position.Margin;
            txt.Location = new Point(0, 2); // position this 2 pixels lower than the button
            txt.Text     = tag.SelectedPath;
            // Button
            Button btn = new Button();

            btn.TabIndex = position.NextTabIndex;
            btn.Name     = "pathButton" + position.TabIndex.ToString();
            btn.Width    = position.WidthColumnTwo;
            btn.Location = new Point(position.StartColumnTwo - position.StartColumnOne, 0); // needs to be relative to the parent
            btn.Text     = LocalizationHelper.CreateLabelProperty("[configuration.browse]").Evaluate();
            // Add events
            txt.Leave += _entryLeave;
            btn.Click += _buttonClicked;
            // Create PathDetails
            PathDetails details = new PathDetails(tag, txt, btn);

            // Set tags
            txt.Tag = details;
            btn.Tag = details;
            // Create and return panel
            Panel panel = details.GetAsPanel(new Size(position.Width, position.LineHeight), new Point(position.StartColumnOne, position.LinePosition));

            panel.TabIndex = position.NextTabIndex;
            panel.Name     = "pathHolder" + position.TabIndex;
            panel.Margin   = new Padding(0);
            return(panel);
        }
コード例 #2
0
        private void ButtonClicked(object sender, EventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            if (sender is Button)
            {
                Button button = (Button)sender;
                if (button.Tag == null)
                {
                    return;
                }
                // Handle a PreferenceList
                if (button.Tag is PreferenceListDetails)
                {
                    PreferenceListDetails details = (PreferenceListDetails)button.Tag;
                    if (details.ListBox.SelectedIndex != -1)
                    {
                        sbyte indexChange;
                        if (button == details.ButtonUp)
                        {
                            indexChange = -1; // one up
                        }
                        else if (button == details.ButtonDown)
                        {
                            indexChange = 1; // one down
                        }
                        else
                        {
                            return; // wrong button?
                        }
                        int selectedIndex = details.ListBox.SelectedIndex;
                        int itemIndex     = details.PreferenceList.Ranking[selectedIndex];
                        details.PreferenceList.Ranking.RemoveAt(selectedIndex);
                        details.PreferenceList.Ranking.Insert(selectedIndex + indexChange, itemIndex);
                        string itemString = details.ListBox.SelectedItem.ToString();
                        details.ListBox.Items.RemoveAt(selectedIndex);
                        details.ListBox.Items.Insert(selectedIndex + indexChange, itemString);
                        details.ListBox.SelectedIndex = selectedIndex + indexChange;
                        _btnSave.Enabled  = true;
                        _btnApply.Enabled = true;
                    }
                }
                // Handle a Path
                else if (button.Tag is PathDetails)
                {
                    PathDetails details = (PathDetails)button.Tag;
                    switch (details.Path.SelectedPathType)
                    {
                    case Path.PathType.FILE:
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.FileName = details.Path.SelectedPath;
                        if (System.IO.File.Exists(ofd.FileName))
                        {
                            ofd.InitialDirectory = System.IO.Path.GetDirectoryName(ofd.FileName);
                        }
                        if (ofd.ShowDialog() == DialogResult.OK)
                        {
                            details.TextBox.Text      = ofd.FileName;
                            details.Path.SelectedPath = ofd.FileName;
                            _btnSave.Enabled          = true;
                            _btnApply.Enabled         = true;
                        }
                        break;

                    case Path.PathType.FOLDER:
                        FolderBrowserDialog fbd = new FolderBrowserDialog();
                        fbd.SelectedPath = details.Path.SelectedPath;
                        if (fbd.ShowDialog() == DialogResult.OK)
                        {
                            details.TextBox.Text      = fbd.SelectedPath;
                            details.Path.SelectedPath = fbd.SelectedPath;
                            _btnSave.Enabled          = true;
                            _btnApply.Enabled         = true;
                        }
                        break;

                    default:
                        return;
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Creates a default Path.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="tag"></param>
 /// <returns></returns>
 private Panel CreateBrowseEntry(Position position, Path tag)
 {
   // TextBox
   TextBox txt = new TextBox();
   txt.TabIndex = position.NextTabIndex;
   txt.Name = "pathTextBox" + position.TabIndex.ToString();
   txt.Width = position.WidthColumnOne - position.Margin;
   txt.Location = new Point(0, 2); // position this 2 pixels lower than the button
   txt.Text = tag.SelectedPath;
   // Button
   Button btn = new Button();
   btn.TabIndex = position.NextTabIndex;
   btn.Name = "pathButton" + position.TabIndex.ToString();
   btn.Width = position.WidthColumnTwo;
   btn.Location = new Point(position.StartColumnTwo - position.StartColumnOne, 0); // needs to be relative to the parent
   btn.Text = LocalizationHelper.CreateLabelProperty("[configuration.browse]").Evaluate();
   // Add events
   txt.Leave += _entryLeave;
   btn.Click += _buttonClicked;
   // Create PathDetails
   PathDetails details = new PathDetails(tag, txt, btn);
   // Set tags
   txt.Tag = details;
   btn.Tag = details;
   // Create and return panel
   Panel panel = details.GetAsPanel(new Size(position.Width, position.LineHeight), new Point(position.StartColumnOne, position.LinePosition));
   panel.TabIndex = position.NextTabIndex;
   panel.Name = "pathHolder" + position.TabIndex;
   panel.Margin = new Padding(0);
   return panel;
 }