這是使用 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 + ;
}
}
}
這個類的代碼是非常簡單的我就不多作解釋了
From:http://tw.wingwit.com/Article/program/net/201311/11868.html