[英]CF TreeView - Selected Item when control loses focus
我知道CF中缺少“ HideSelection”屬性。 但是當選擇一個項目時,即使控件失去焦點,我仍然需要處理使其保持選中狀態(灰色)的情況。
我嘗試使用這種和平的代碼,但沒有成功。 我在GetFocus()方法中遇到異常,我不知道自己在做什么錯。
任何幫助深表感謝 !
[DllImport("User32.dll")]
static extern IntPtr GetFocus();
[DllImport("User32.dll")]
static extern Int32 GetWindowLong(IntPtr hwnd, Int32 integer1);
[DllImport("User32.dll")]
static extern IntPtr SetWindowLong(IntPtr hwnd, Int32 integer1, int integer2);
private bool doneOnce;
protected override void OnGotFocus(System.EventArgs e)
{
base.OnGotFocus(e);
if (this.itemsTreeView != null)
{
this.itemsTreeView.Focus();
if (doneOnce == false)
{
doneOnce = true;
IntPtr hWnd = GetFocus();
Int32 lS = GetWindowLong(hWnd, -16);
lS = lS | 0x20;
SetWindowLong(hWnd, -16, lS);
}
}
}
我已將此代碼放在保存TreeView控件的“代碼隱藏”視圖中。
Windows CE使用coredll.dll而不是user32.dll 。
某些功能在兩個平台上均相等,而某些功能未針對Compact Framework實施。 我通常檢查http://www.pinvoke.net上的聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.