在Windows Mobile 6.5上运行的Compact Framework 3.5中TreeView上的树节点检查行为 [英] Tree Node Checked behavior on a TreeView in Compact Framework 3.5 running on Windows Mobile 6.5

查看:91
本文介绍了在Windows Mobile 6.5上运行的Compact Framework 3.5中TreeView上的树节点检查行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在升级现有的.NET Windows Mobile应用程序,以使用紧凑版框架的3.5版并在Windows Mobile 6.5上运行.我有一个带有TreeView的表单. TreeView.Checkboxes属性设置为true,以便每个节点都有一个复选框.这在Windows Mobile的所有早期版本中都没有问题.

I have been upgrading an existing .NET Windows Mobile application to use the 3.5 version of the compact framework and to run on Windows Mobile 6.5. I have a form with a TreeView. The TreeView.Checkboxes property is set to true so that each node has a check box. This gives no trouble in all previous versions of Windows Mobile.

但是,在6.5版中,当您单击一个复选框时,它似乎会立即选中然后取消选中.但是它仅引发一次AfterCheck事件.我能拿到支票的唯一方法是双击它(这是错误的行为).

However, in version 6.5 when you click on a check box it appears to check and then uncheck instantaneously. But it only raises the AfterCheck event once. The only way I can get a check to stick is by double clicking it (which is the wrong behavior).

有人看到过这种行为吗?有谁知道解决方法?

Has anyone seen this behavior? Does anyone know of a workaround for it?

我提供了一个简单的测试表格.将此表单转储到针对Windows Mobile 6的Visual Studio 2008智能设备应用程序中,以了解我的意思.

I have included a simple test form. Dump this form into a Visual Studio 2008 Smart Device application targeted at Windows Mobile 6 to see what I mean.

Public Class frmTree
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Sub New()
    MyBase.new()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

End Sub

'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing AndAlso components IsNot Nothing Then
        components.Dispose()
    End If
    MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
Private mainMenu1 As System.Windows.Forms.MainMenu

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Dim TreeNode1 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node0")
    Dim TreeNode2 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node2")
    Dim TreeNode3 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node3")
    Dim TreeNode4 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node4")
    Dim TreeNode5 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node1")
    Dim TreeNode6 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node5")
    Dim TreeNode7 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node6")
    Dim TreeNode8 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node7")
    Me.mainMenu1 = New System.Windows.Forms.MainMenu
    Me.TreeView1 = New System.Windows.Forms.TreeView
    Me.SuspendLayout()
    '
    'TreeView1
    '
    Me.TreeView1.CheckBoxes = True
    Me.TreeView1.Location = New System.Drawing.Point(37, 41)
    Me.TreeView1.Name = "TreeView1"
    TreeNode2.Text = "Node2"
    TreeNode3.Text = "Node3"
    TreeNode4.Text = "Node4"
    TreeNode1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode2, TreeNode3, TreeNode4})
    TreeNode1.Text = "Node0"
    TreeNode6.Text = "Node5"
    TreeNode7.Text = "Node6"
    TreeNode8.Text = "Node7"
    TreeNode5.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode6, TreeNode7, TreeNode8})
    TreeNode5.Text = "Node1"
    Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode1, TreeNode5})
    Me.TreeView1.Size = New System.Drawing.Size(171, 179)
    Me.TreeView1.TabIndex = 0
    '
    'frmTree
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
    Me.AutoScroll = True
    Me.ClientSize = New System.Drawing.Size(240, 268)
    Me.Controls.Add(Me.TreeView1)
    Me.Menu = Me.mainMenu1
    Me.Name = "frmTree"
    Me.Text = "frmTree"
    Me.ResumeLayout(False)

End Sub
#End Region

End Class

推荐答案

我能够为此创建解决方法,但必须采取极端措施.看来发生这种现象是因为从MouseDown和MouseUp事件中都触发了Click事件(而不是像Windows或以前版本中那样,只是将鼠标向上).

I was able to create a workaround for this, but had to go to extreme measures to do so. It appears that the behavior we are seeing occurs because the Click event is being fired both from the MouseDown and the MouseUp events (instead of just the mouse up as it would in Windows or previous versions).

要显示此内容,您可以先点击复选框,然后将手指放在屏幕上,然后将其拖出.它将从MouseDown事件变为选中状态,并且将保持选中状态,因为当您从其他位置抬起手指时,不会触发MouseUp事件.点击复选框并继续拖动,效果相同.

To show this, you can start by tapping on the checkbox, leaving your finger on the screen and dragging off the check box. It will become checked from the MouseDown event and will stay checked because the MouseUp event is not fired when you lift your finger from a different position. The same works for tapping off the checkbox and dragging on.

为了防止双击行为,您必须禁止MouseDown或MouseUp事件之一.我最终创建了一个继承TreeView并使用WndProcHooker钩住OnMouseDown方法并将其标记为已处理的控件,从而使MouseDown事件永远不会被触发.我认为这是最有意义的(抬起该复选框时,您必须将手指放在该复选框上).

In order to prevent the double click behavior you must suppress one of the MouseDown or MouseUp events. I ended up creating a control that inherited the TreeView and used WndProcHooker to hook the OnMouseDown method and mark it as handled so that the MouseDown Event never actually gets fired. I figured that made the most sense (you must have your finger over the checkbox when you lift it).

此处是指向有关WndProcHooker的 MSDN文章的链接.下面是我的TreeViewInherit类的代码.虽然这行得通,但我仍然感到惊讶,这是我必须花费的时间才能使它正常工作.此外,我不希望MS修复此问题,从而中断了我的解决方法.

Here is a link to the MSDN article about the WndProcHooker. Below is my code for my TreeViewInherit class. While this works, I am still astonished that these are the lengths I have to go to to get this working. Additionally, I am not looking forward to the day MS fixes this and thus breaks my workaround in the process.

    Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms

Public Class TreeViewInherit
    Inherits System.Windows.Forms.TreeView

#Region " Variables "
    Private mBlnHandleMouseDown As Boolean
#End Region

#Region " Methods "

    Public Sub New()
    MyBase.New()

    'Set the Handle Mouse Down based on the OS. if 6.5 and up, then handle it.
    mBlnHandleMouseDown = (System.Environment.OSVersion.Version.Major >= 5 AndAlso System.Environment.OSVersion.Version.Minor >= 2 AndAlso System.Environment.OSVersion.Version.Build >= 21234)
    If mBlnHandleMouseDown Then
        WndProcHooker.HookWndProc(Me, New WndProcHooker.WndProcCallback(AddressOf Me.WM_LButtonDown_Handler), Win32.WM_LBUTTONDOWN)
    End If
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
    'Don't Call the Base to prevent the extra event from firing
    If Not mBlnHandleMouseDown Then
        MyBase.OnMouseDown(e)
    End If
    End Sub

#End Region

#Region " Events "
    Private Function WM_LButtonDown_Handler(ByVal hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer, ByRef handled As Boolean) As Integer
    Try
        Me.Capture = False

        Dim lastCursorCoordinates As Win32.POINT = Win32.LParamToPoint(lParam)
        If Me.ClientRectangle.Contains(lastCursorCoordinates.X, lastCursorCoordinates.Y) Then
        OnMouseDown(New MouseEventArgs(MouseButtons.Left, 1, lastCursorCoordinates.X, lastCursorCoordinates.Y, 0))
        End If
        handled = True
        Return 0
    Catch ex As Exception
        Throw
    End Try
    End Function
#End Region

End Class

祝你好运!

这篇关于在Windows Mobile 6.5上运行的Compact Framework 3.5中TreeView上的树节点检查行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆