在这篇文章中,介绍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源程序这个类的代码是非常简单的,我就不多作解释了。
本文名称:C#ConfigDlg.cs源程序
分享路径:http://www.shufengxianlan.com/qtweb/news41/363841.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联