使用 C# 开发智能手机软件:推箱子(十六)

2007年10月09日 11:22:00
这是" 使用 C# 开发智能手机软件:推箱子" 系列文章的第十六篇。在这篇文章中,介绍 Window/ConfigDlg.cs 源程序文件。这个源程序文件包含 ConfigDlg 类,该类继承自 System.Windows.Forms.Form 类,表示推箱子的"配置"对话框。如下图所示:



下面是 Window/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;
}
}

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

1 using System;
2 using System.Windows.Forms;
3
4 namespace Skyiv.Ben.PushBox.Window
5 {
6 /// >summary<
7 /// "配置"对话框
8 /// >/summary<
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 }
78 }

这个类的代码是非常简单的,我就不多作解释了。她只是一个用户界面,实际工作在 Skyiv.Ben.PushBox.Common.ConfigFile 类中完成,请参见:" 使用 C# 开发智能手机软件:推箱子(九)"。

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1816525


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值