這是我的答案的相關代碼。
部分代碼: 形式A(原始調用的形式)
If CurMode = Browse Then
'Check for Quick List menu CRTL-Q
If e.Control AndAlso e.KeyCode = Keys.Q Then
' Call the 'Menu form, FormB
CType(Me.MdiParent, frmRECORDmain).ShowQuickListMenu(Me, Me.ActiveControl)
Exit Sub
End If
在[快速菜單形式(原始形態B)
Public Class frmQuickListMENU
Dim CallingForm As Form
Dim CallingControl As Control
Dim Selection As String
' This is so that Form B will know who Form A was.
Overloads Sub Show(ByVal f As Form,
ByVal c As Control,
Optional PreSelection As String = "")
CallingForm = f
CallingControl = c
Selection = PreSelection
Show()
End Sub
Private Sub frmQuickListMENU_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.D1, Keys.NumPad1
. .
Case Keys.D3, Keys.NumPad3
. . .
Case Keys.D6, Keys.NumPad6
. . .
' One of 12 Menu choices which will open 1 of 12 Form C's
Case Keys.D7, Keys.NumPad7
Dim frmquickListPHD1 As New frmQuickListPHD()
frmquickListPHD1.MdiParent = MasterParentForm
frmquickListPHD1.StartPosition = FormStartPosition.Manual
frmquickListPHD1.Location = New Point(QLPHD.Left, QLPHD.Top)
' Show Form C
frmquickListPHD1.Show(CallingForm, CallingControl, Me)
End Select
' ************************
' ************************
' THE NEXT LINE IS THE 'MAGIC' I WAS LOOKING FOR
' This line returnbs focus back to the original Form A
' ************************
CType(CallingForm, Windows.Forms.Form).Focus()
Me.Close()
End Sub
Private Sub frmQuickListMENU_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim x1 As Integer
x1 = Me.Width
End Sub
End Class
終於爲「快速列表的代碼' - 表格C 但是,由於我決定改變表格B代碼而不是表格C代碼的焦點,因此表格C代碼都不相關。我只顯示它與我原來的帖子一致。
Dim callingform As Form
Dim callingcontrol As Control
Dim MenuForm As Form
' The following was initially required so that the change of focus could be made within this
' Class but I have since changed my mind and the Overload is unnecessary. I only left
' this here so the code would be consistent with my original note. I'll be removing
' thisOverload of the 'Show' event.
Overloads Sub Show(ByVal f1 As Form,
ByVal c As Control,
ByVal f2 As Form)
callingform = f1
MenuForm = f2
callingcontrol = c
Show()
End Sub
Private Sub frmQuickListPHD_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
conn.Open()
DA.SelectCommand = New SqlCommand(SQL, conn)
'
'
'
Catch ex As Exception
Console.WriteLine("Error" & ex.ToString)
Finally
conn.Close()
End Try
Me.Height = QLPHD.Height
Me.Width = QLPHD.Width
'
'
' More form layout code
'
'
'
End Sub
End Class
謝謝您花時間發佈這個問題和答案。你會考慮發佈源代碼嗎?我發現這有點難以遵循,代碼清單可能會讓事情變得更加清晰。 –