C# ConfigDlg.cs源程序

开发 后端
本文介绍C# ConfigDlg.cs源程序,这个源程序文件包含 ConfigDlg 类,该类继承自 System.Windows.Forms.Form 类。

在这篇文章中,介绍C# ConfigDlg.cs源程序文件。这个源程序文件包含 ConfigDlg 类,该类继承自 System.Windows.Forms.Form 类。

下面是C# ConfigDlg.Designer.cs源程序的部分代码:

  1. namespace Skyiv.Ben.PushBox.Window  
  2. {  
  3. partial class ConfigDlg  
  4. {  
  5. private void InitializeComponent()  
  6. {  
  7. // 注意:省略了一些代码  
  8.  
  9. this.btnSave.DialogResult = System.Windows.Forms.DialogResult.OK;  
  10. this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;  
  11. this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);  
  12. this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);  
  13. this.btnUp.Click += new System.EventHandler(this.btnUp_Click);  
  14. this.btnDown.Click += new System.EventHandler(this.btnDown_Click);  
  15. }  
  16.  
  17. private System.Windows.Forms.ListBox lbxGroup;  
  18. private System.Windows.Forms.TextBox tbxGroup;  
  19. private System.Windows.Forms.Button btnSave;  
  20. private System.Windows.Forms.Button btnCancel;  
  21. private System.Windows.Forms.Button btnAdd;  
  22. private System.Windows.Forms.Button btnDelete;  
  23. private System.Windows.Forms.Button btnUp;  
  24. private System.Windows.Forms.Button btnDown;  
  25. }  
  26. }  

下面是C# ConfigDlg.cs源程序代码:

  1. using System;  
  2. using System.Windows.Forms;  
  3.  
  4. namespace Skyiv.Ben.PushBox.Window  
  5. {  
  6. ///  
  7. /// “配置”对话框  
  8. ///  
  9. public partial class ConfigDlg : Form  
  10. {  
  11. public ConfigDlg(bool isTopMost)  
  12. {  
  13. InitializeComponent();  
  14. TopMost = isTopMost;  
  15. }  
  16.  
  17. public string[] Groups  
  18. {  
  19. get  
  20. {  
  21. string[] groups = new string[lbxGroup.Items.Count];  
  22. for (int i = 0; i < lbxGroup.Items.Count; i++) groups[i] = lbxGroup.Items[i].ToString();  
  23. return groups;  
  24. }  
  25. set  
  26. {  
  27. if (value != null)  
  28. {  
  29. lbxGroup.BeginUpdate();  
  30. foreach (string group in value) lbxGroup.Items.Add(group);  
  31. lbxGroup.EndUpdate();  
  32. if (lbxGroup.Items.Count > 0) lbxGroup.SelectedIndex = 0;  
  33. }  
  34. }  
  35. }  
  36.  
  37. private void btnAdd_Click(object sender, EventArgs e)  
  38. {  
  39. string s = tbxGroup.Text.Trim();  
  40. if (s.Length == 0) return;  
  41. int idx = lbxGroup.SelectedIndex;  
  42. if (idx < 0)  
  43. {  
  44. lbxGroup.Items.Add(s);  
  45. idx = lbxGroup.Items.Count - 1;  
  46. }  
  47. else lbxGroup.Items.Insert(idx, s);  
  48. lbxGroup.SelectedIndex = idx;  
  49. }  
  50.  
  51. private void btnDelete_Click(object sender, EventArgs e)  
  52. {  
  53. int idx = lbxGroup.SelectedIndex;  
  54. if (idx < 0) return;  
  55. lbxGroup.Items.RemoveAt(idx);  
  56. if (lbxGroup.Items.Count <= 0) return;  
  57. lbxGroup.SelectedIndex = (idx < lbxGroup.Items.Count) ? idx : (idx - 1);  
  58. }  
  59.  
  60. private void btnUp_Click(object sender, EventArgs e)  
  61. {  
  62. int idx = lbxGroup.SelectedIndex;  
  63. if (idx < 1) return;  
  64. lbxGroup.Items.Insert(idx - 1, lbxGroup.SelectedItem);  
  65. lbxGroup.Items.RemoveAt(idx + 1);  
  66. lbxGroup.SelectedIndex = idx - 1;  
  67. }  
  68.  
  69. private void btnDown_Click(object sender, EventArgs e)  
  70. {  
  71. int idx = lbxGroup.SelectedIndex;  
  72. if (idx < 0    idx >= lbxGroup.Items.Count - 1) return;  
  73. lbxGroup.Items.Insert(idx + 2, lbxGroup.SelectedItem);  
  74. lbxGroup.Items.RemoveAt(idx);  
  75. lbxGroup.SelectedIndex = idx + 1;  
  76. }  
  77. }  

C# ConfigDlg.cs源程序这个类的代码是非常简单的,我就不多作解释了。

【编辑推荐】

  1. C#数据库查询和操作大全
  2. 浅析C#扩展方法
  3. C# Singleton的使用及优缺点探讨
  4. 详细分析C#数据库连接池
  5. C#数据库备份及还原的实现代码
责任编辑:佚名 来源: IT168
相关推荐

2009-08-20 10:54:29

C#做浏览器源程序

2009-08-24 18:06:36

源程序代码C#读取XML文件

2010-01-15 17:18:57

C++源程序

2010-01-28 09:31:57

C++开源程序

2009-08-13 17:04:09

C#语言C#程序

2009-08-20 17:49:53

学习C#程序

2009-08-19 17:11:49

C#程序集

2009-08-24 15:46:46

C# SmartPho

2009-08-12 18:28:09

C#事件处理程序

2009-08-12 17:44:30

C# Web Serv

2009-08-20 10:48:05

C#做Screen C

2009-08-13 17:15:44

C#屏幕保护程序

2009-08-07 17:32:17

C#编译程序

2009-08-12 18:20:39

C#事件驱动程序

2009-08-14 11:00:16

C#创建Windows

2009-08-24 09:25:18

Visual C# ..NET应用程序

2009-08-26 15:10:34

脱离.net fram

2009-08-28 16:03:15

C#程序实现鼠标移动

2009-08-25 17:24:55

C#串口通信程序

2009-08-24 14:19:27

C# Windows应
点赞
收藏

51CTO技术栈公众号