2

任意のフォームのシステム メニューに「About...」ボタンを追加できるクラスを作成できました。loadこの部分は、フォームのイベントによって追加されたボタンで正常に動作しますが、そのボタンのクリックをどのように処理すればよいでしょうか? ありがとう。

ボタンを追加する方法は次のとおりです-

Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    {More code....}
    Dim SysMenu = New SystemMenu(Me)
    {More code....}

End Sub

そして、ここにSystemMenuクラスがあります -

Imports System.Windows.Forms

Public Class SystemMenu

    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
    Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As IntPtr, ByVal uFlags As Int32, ByVal uIDNewItem As IntPtr, ByVal lpNewItem As String) As Boolean
    Private Const MF_STRING As Integer = &H0
    Private Const MF_SEPARATOR As Integer = &H800

    Private m_hSysMenu As IntPtr
    Private Property hSysMenu() As IntPtr
        Get
            Return Me.m_hSysMenu
        End Get
        Set(ByVal Value As IntPtr)
            Me.m_hSysMenu = Value
        End Set
    End Property

    '**
    ' Constructor
    '*
    Protected Friend Sub New(ByRef Form As Form)
        Me.hSysMenu = GetSystemMenu(Form.Handle, False)
        AddAbout(Form)
    End Sub

    '**
    ' Add an 'About' button to the system menu of the given form
    '*
    Private Sub AddAbout(ByRef Form As Form)
        AppendMenu(Me.hSysMenu, MF_SEPARATOR, 1000, Nothing)
        AppendMenu(Me.hSysMenu, MF_STRING, 1001, "About...")
    End Sub

End Class
4

1 に答える 1