日期:2014-05-18  浏览次数:20903 次

有没有精同多个子窗体情况下的快捷键问题的达人?
本人在一个父窗体中打开了子窗体form1和子窗体form2,form1中有个按钮(【导出】并设置了快捷键s),form2中有个按钮(【删除】也设置了快捷键s),当前焦点在form2上使用alt+s为什么会响应form1上的【导出】按钮,而form2中的【删除】按钮确没有反应,求精通人士解答。

------解决方案--------------------
我用以下代码简单测试了一下,没有发现lz所说的那个问题啊。
VB.NET code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frmA As New FormA
        frmA.Show()
        Dim frmB As New FormB
        frmB.Show()
    End Sub

End Class

Public Class FormA
    Inherits System.Windows.Forms.Form

    Public Sub New()
        Dim btn As New Button
        btn.Text = "Button(&S)"
        AddHandler btn.Click, AddressOf ButtonClick
        Me.Controls.Add(btn)
        Me.Text = "FormA"
    End Sub

    Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("FormA")
    End Sub

End Class

Public Class FormB
    Inherits System.Windows.Forms.Form

    Public Sub New()
        Dim btn As New Button
        btn.Text = "Button(&S)"
        AddHandler btn.Click, AddressOf ButtonClick
        Me.Controls.Add(btn)
        Me.Text = "FormB"
    End Sub

    Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("FormB")
    End Sub

End Class

------解决方案--------------------
VB.NET code

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim frmA As New FormA
        Dim frmB As New FormB

        Dim panel1 As New Panel
        panel1.Dock = DockStyle.Fill
        panel1.Controls.Add(frmA)
        panel1.Controls.Add(frmB)

        frmA.Location = New Point(10, 10)
        frmB.Location = New Point(10, frmA.Location.Y + frmA.Height + 10)
        Me.Controls.Add(panel1)
    End Sub
End Class

Public Class FormA
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
        Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle

        Dim btn As New Button
        btn.Text = "ButtonA(&S)"
        AddHandler btn.Click, AddressOf ButtonClick
        Me.Controls.Add(btn)
        Me.Text = "FormA"
    End Sub

    Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("FormA")
    End Sub

End Class

Public Class FormB
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
        Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle

        Dim btn As New Button
        btn.Text = "ButtonB(&S)"
        AddHandler btn.Click, AddressOf ButtonClick
        Me.Controls.Add(btn)
        Me.Text = "FormB"
    End Sub

    Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("FormB")
    End Sub

End Class

------解决方案--------------------
注意这两处:
1、Public Class FormA
Inherits System.Windows.Forms.UserControl


2、Public Class FormB
Inherits System.Windows.Forms.UserControl