在上面的代碼中我用ParseCtlID方 法來得到控件相對應的屬性名.
在繼續完成這類之前我需要寫一個接口IControl來統 一訪問WinForm Control和WebForm Control類的屬性和方法.
//一下五個using語句用 來減少輸入
using WebFormH = System.Web.UI.HtmlControls;
using WebFormW = System.Web.UI.WebControls;
using WinForms = System.Windows.Forms;
using WebCtl = System.Web.UI.Control;
using WinCtl = System.Windows.Forms.Control;
//統一訪問接口
interface IControl
{
object RealCtl //得到真實的控件對象
{
get;
}
string GetCtlID(); //得到控件 ID
IEnumerable<IControl> GetSubCtls(); //得到子控件集合
}
struct WebControl : IControl
{
WebCtl _ctl;
public object RealCtl
{
get { return this._ctl; }
}
public WebControl(WebCtl ctl)
{
this._ctl = ctl;
}
public string GetCtlID()
{
return this._ctl.ID;
}
public IEnumerable<IControl> GetSubCtls()
{
foreach (WebCtl c in this._ctl.Controls)
yIEld return new WebControl(c);
}
};
struct WinControl : IControl
{
WinCtl _ctl;
public object RealCtl
{
get { return this._ctl; }
}
public WinControl(WinCtl ctl)
{
this._ctl = ctl;
}
public string GetCtlID()
{
return this._ctl.Name;
}
public IEnumerable<IControl> GetSubCtls()
{
foreach (WinCtl c in this._ctl.Controls)
yIEld return new WinControl(c);
}
};