十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
在这篇文章中,介绍C# ConfigDlg.cs源程序文件。这个源程序文件包含 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源程序这个类的代码是非常简单的,我就不多作解释了。