这是使用 C# 开发智能手机软件推箱子 在这篇文章中介绍 Window/ConfigDlgcs 源程序文件这个源程序文件包含 ConfigDlg 类该类继承自 SystemWindowsFormsForm 类表示推箱子的配置对话框如下图所示
下面是 Window/ConfigDlgDesignercs 的源程序的部分代码
namespace SkyivBenPushBoxWindow
{
partial class ConfigDlg
{
private void InitializeComponent()
{
// 注意省略了一些代码
thisbtnSaveDialogResult = SystemWindowsFormsDialogResultOK;
thisbtnCancelDialogResult = SystemWindowsFormsDialogResultCancel;
thisbtnAddClick += new SystemEventHandler(thisbtnAdd_Click);
thisbtnDeleteClick += new SystemEventHandler(thisbtnDelete_Click);
thisbtnUpClick += new SystemEventHandler(thisbtnUp_Click);
thisbtnDownClick += new SystemEventHandler(thisbtnDown_Click);
}
private SystemWindowsFormsListBox lbxGroup;
private SystemWindowsFormsTextBox tbxGroup;
private SystemWindowsFormsButton btnSave;
private SystemWindowsFormsButton btnCancel;
private SystemWindowsFormsButton btnAdd;
private SystemWindowsFormsButton btnDelete;
private SystemWindowsFormsButton btnUp;
private SystemWindowsFormsButton btnDown;
}
}
下面是 ConfigDlgcs 的源程序代码
using System;
using SystemWindowsForms;
namespace SkyivBenPushBoxWindow
{
///
/// 配置对话框
///
public partial class ConfigDlg : Form
{
public ConfigDlg(bool isTopMost)
{
InitializeComponent();
TopMost = isTopMost;
}
public string[] Groups
{
get
{
string[] groups = new string[lbxGroupItemsCount];
for (int i = ; i < lbxGroupItemsCount; i++) groups[i] = lbxGroupItems[i]ToString();
return groups;
}
set
{
if (value != null)
{
lbxGroupBeginUpdate();
foreach (string group in value) lbxGroupItemsAdd(group);
lbxGroupEndUpdate();
if (lbxGroupItemsCount > ) lbxGroupSelectedIndex = ;
}
}
}
private void btnAdd_Click(object sender EventArgs e)
{
string s = tbxGroupTextTrim();
if (sLength == ) return;
int idx = lbxGroupSelectedIndex;
if (idx < )
{
lbxGroupItemsAdd(s);
idx = lbxGroupItemsCount ;
}
else lbxGroupItemsInsert(idx s);
lbxGroupSelectedIndex = idx;
}
private void btnDelete_Click(object sender EventArgs e)
{
int idx = lbxGroupSelectedIndex;
if (idx < ) return;
lbxGroupItemsRemoveAt(idx);
if (lbxGroupItemsCount <= ) return;
lbxGroupSelectedIndex = (idx < lbxGroupItemsCount) ? idx : (idx );
}
private void btnUp_Click(object sender EventArgs e)
{
int idx = lbxGroupSelectedIndex;
if (idx < ) return;
lbxGroupItemsInsert(idx lbxGroupSelectedItem);
lbxGroupItemsRemoveAt(idx + );
lbxGroupSelectedIndex = idx ;
}
private void btnDown_Click(object sender EventArgs e)
{
int idx = lbxGroupSelectedIndex;
if (idx < idx >= lbxGroupItemsCount ) return;
lbxGroupItemsInsert(idx + lbxGroupSelectedItem);
lbxGroupItemsRemoveAt(idx);
lbxGroupSelectedIndex = idx + ;
}
}
}
这个类的代码是非常简单的我就不多作解释了