C# ConfigDlg.cs源程序
作者:佚名
本文介紹C# ConfigDlg.cs源程序,這個(gè)源程序文件包含 ConfigDlg 類,該類繼承自 System.Windows.Forms.Form 類。
在這篇文章中,介紹C# ConfigDlg.cs源程序文件。這個(gè)源程序文件包含 ConfigDlg 類,該類繼承自 System.Windows.Forms.Form 類。
下面是C# ConfigDlg.Designer.cs源程序的部分代碼:
- namespace Skyiv.Ben.PushBox.Window
- {
- partial class ConfigDlg
- {
- private void InitializeComponent()
- {
- // 注意:省略了一些代碼
- this.btnSave.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
- this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
- this.btnUp.Click += new System.EventHandler(this.btnUp_Click);
- this.btnDown.Click += new System.EventHandler(this.btnDown_Click);
- }
- private System.Windows.Forms.ListBox lbxGroup;
- private System.Windows.Forms.TextBox tbxGroup;
- private System.Windows.Forms.Button btnSave;
- private System.Windows.Forms.Button btnCancel;
- private System.Windows.Forms.Button btnAdd;
- private System.Windows.Forms.Button btnDelete;
- private System.Windows.Forms.Button btnUp;
- private System.Windows.Forms.Button btnDown;
- }
- }
下面是C# ConfigDlg.cs源程序代碼:
- using System;
- using System.Windows.Forms;
- namespace Skyiv.Ben.PushBox.Window
- {
- ///
- /// “配置”對話框
- ///
- public partial class ConfigDlg : Form
- {
- public ConfigDlg(bool isTopMost)
- {
- InitializeComponent();
- TopMost = isTopMost;
- }
- public string[] Groups
- {
- get
- {
- string[] groups = new string[lbxGroup.Items.Count];
- for (int i = 0; i < lbxGroup.Items.Count; i++) groups[i] = lbxGroup.Items[i].ToString();
- return groups;
- }
- set
- {
- if (value != null)
- {
- lbxGroup.BeginUpdate();
- foreach (string group in value) lbxGroup.Items.Add(group);
- lbxGroup.EndUpdate();
- if (lbxGroup.Items.Count > 0) lbxGroup.SelectedIndex = 0;
- }
- }
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- string s = tbxGroup.Text.Trim();
- if (s.Length == 0) return;
- int idx = lbxGroup.SelectedIndex;
- if (idx < 0)
- {
- lbxGroup.Items.Add(s);
- idx = lbxGroup.Items.Count - 1;
- }
- else lbxGroup.Items.Insert(idx, s);
- lbxGroup.SelectedIndex = idx;
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- int idx = lbxGroup.SelectedIndex;
- if (idx < 0) return;
- lbxGroup.Items.RemoveAt(idx);
- if (lbxGroup.Items.Count <= 0) return;
- lbxGroup.SelectedIndex = (idx < lbxGroup.Items.Count) ? idx : (idx - 1);
- }
- private void btnUp_Click(object sender, EventArgs e)
- {
- int idx = lbxGroup.SelectedIndex;
- if (idx < 1) return;
- lbxGroup.Items.Insert(idx - 1, lbxGroup.SelectedItem);
- lbxGroup.Items.RemoveAt(idx + 1);
- lbxGroup.SelectedIndex = idx - 1;
- }
- private void btnDown_Click(object sender, EventArgs e)
- {
- int idx = lbxGroup.SelectedIndex;
- if (idx < 0 idx >= lbxGroup.Items.Count - 1) return;
- lbxGroup.Items.Insert(idx + 2, lbxGroup.SelectedItem);
- lbxGroup.Items.RemoveAt(idx);
- lbxGroup.SelectedIndex = idx + 1;
- }
- }
- }
C# ConfigDlg.cs源程序這個(gè)類的代碼是非常簡單的,我就不多作解釋了。
【編輯推薦】
責(zé)任編輯:佚名
來源:
IT168