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

然而,在版本 6.5 中,当您单击复选框时,它似乎会立即选中,然后立即取消选中。但它只会引发一次 AfterCheck 事件。我可以粘住支票的唯一方法是双击它(这是错误的行为)。

有人见过这种行为吗?有谁知道它的解决方法?

我附上了一份简单的测试表格。将此表单转储到针对 Windows Mobile 6 的 Visual Studio 2008 智能设备应用程序中即可明白我的意思。

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
有帮助吗?

解决方案 2

我能够创建一个解决方法这一点,但不得不采取极端措施来这样做。看来,发生我们所看到的行为,因为Click事件正在无论从鼠标按下和鼠标松开事件(而不是只老鼠了,因为它会在Windows或以前的版本)。

解雇

要证明这一点,您可以通过点击复选框,让你的手指在屏幕上并拖动关闭复选框开始。它将成为从MouseDown事件检查,将保持选中状态,因为当你从不同的位置抬起手指不激发MouseUp事件。用于分接的复选框并拖动同一作品。

为了防止你必须抑制的MouseDown或事件的MouseUp之一的双击行为。我结束了创建继承TreeView和用于WndProcHooker挂钩的onmousedown事件方法并将其标记为使MouseDown事件实际上从未被解雇处理的控制。我想,才是最有意义的(你必须有你的手指的复选框,当你提起它)。

下面是将 MSDN文章有关WndProcHooker 一个链路。下面是我为我的TreeViewInherit类代码。虽然这工作,我仍然感到惊讶的是,这些都是我必须去得到这个工作的长度。此外,我并不期待这一天MS修复它,从而打破我的解决办法的过程中。

    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

祝您好运!

其他提示

Hydroslide:来回答你的第一个问题,是的,我看到的这种行为。你的第二个问题:不,我还没有找到一个解决方案。

我已经开发了一个应用程序在VS2K8针对CF3.5sp1.喜欢你的应用程序,排雷是用于几个世代的设备,没有任何问题。然而,我遇到这个树视图的问题上Windows移动6.5.

在我所有的窗口管理6.5电话(用纯(ST6356),倾斜2和宏达Imagio)--以及在WM6.5模拟器--树视图的框功能失败。点击一个框几乎总是导致勾被设定只要清除的毫秒之后(反之亦然).只有这样我已经找到了可靠的力标记为"棒"是双点的选项。听起来很熟悉,Hydroslide?

除了这一奇怪行为,这些TreeViews改变的较新的宏达电话,包括增加之间的空白点,大概是为了便于操纵通过一个手指或拇指。比较:@http://ftp.agconnections.com/treeviews.png.(删除@前的链接。必要的,因为计算器的第一个鼓励我的员额问题,这是"详细和具体的",然后阻止我从创建一个职位,包括一个以上的超链接。好的。) 有趣的是,窗口管理6.5模拟器显示树视图,没有任何额外的空白,但仍然表现出的检查/取消的问题。

我已经创建了一个准系统项目只包含一个标准的树视图和一些节点,并且其行为是相同的我的生产项目: http://ftp.agconnections.com/TreeViewTest.zip.我设置一个断点在AfterCheck事件,并找到--正如Hydroslide没有-那它只发射了一次单一的攻。

我很吃惊,没有一个外部的两个我们有抱怨的这种行为。

客户在等待一个解决这一问题开始堆积起来,并且他们几个都有些不太了解。任何建议是极大的赞赏。

杰森*赛尔

要拿到过AfterCheck事件不触发我发现,我能得到的节点点击,然后用它来调用AfterCheck的问题,即工作,但后来我发现复选框的状态已改变之前AfterCheck被称为这样反而提出了我自己的事件,并妥善处理它。


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

Public Class TreeViewInherit
    Inherits System.Windows.Forms.TreeView

    'Occurs when the user clicks a TreeNode with the mouse.
    Public Event MouseDownOveride(ByVal node As TreeNode)

#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


    Private Function FindTreeNodeFromHandle(ByVal tnc As TreeNodeCollection, ByVal handle As IntPtr) As TreeNode
        For Each tn As TreeNode In tnc
            If tn.Handle = handle Then
                Return tn
            End If
            ' we couldn't have clicked on a child of this node if this node
            ' is not expanded!
            If tn.IsExpanded Then
                Dim tn2 As TreeNode = FindTreeNodeFromHandle(tn.Nodes, handle)
                If tn2 IsNot Nothing Then
                    Return tn2
                End If
            End If
        Next
        Return Nothing
    End Function


#End Region

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

            Dim lastCursorCoordinates As Win32.POINT = Win32.LParamToWin32POINT(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


            Dim msgPos As Point = Win32.LParamToPoint(CInt(Win32.GetMessagePos()))
            msgPos = Me.PointToClient(msgPos)

            ' check to see if the click was on an item
            Dim hti As New Win32.TVHITTESTINFO()
            hti.pt.X = msgPos.X
            hti.pt.Y = msgPos.Y
            Dim hitem As Integer = Win32.SendMessage(Me.Handle, Win32.TVM_HITTEST, 0, hti)
            Dim htMask As UInteger = (Win32.TVHT_ONITEMICON Or Win32.TVHT_ONITEMLABEL Or Win32.TVHT_ONITEMINDENT Or Win32.TVHT_ONITEMBUTTON Or Win32.TVHT_ONITEMRIGHT Or Win32.TVHT_ONITEMSTATEICON)

            If hti.flags = Win32.TVHT_ONITEMSTATEICON Then
                RaiseEvent MouseDownOveride(FindTreeNodeFromHandle(Me.Nodes, hti.hItem))
            End If


            Return 0
        Catch ex As Exception
            Throw
        End Try
    End Function
#End Region

End Class

工程确定。

我们问MS的答案,他们给了我们这涉及捕获点击检查,或根据需要取消选中该复选框一种解决方法。有不累还,但如果它的工作我会后这一点。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top