Как добавить кнопку в заголовок окна - Visual Basic .NET

Формулировка задачи:

Можно ли как нибудь добавить свою кнопку в заголовок ока?

Код к задаче: «Как добавить кнопку в заголовок окна - Visual Basic .NET»

textual
Public Class Form1
 
    Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.Style = cp.Style And Not &HC00000
            Return cp
        End Get
    End Property
 
    Private m_WindowState As FormWindowState = FormWindowState.Normal
    Private m_FormSizeAndLocation As Rectangle = Rectangle.Empty
 
    Private Sub ChangeWindowState(p_NewState As FormWindowState)
        Me.WindowState = FormWindowState.Normal
        Select Case p_NewState
            Case FormWindowState.Maximized
                If m_WindowState = FormWindowState.Normal Then
                    m_FormSizeAndLocation.Location = Me.Location
                    m_FormSizeAndLocation.Size = Me.Size
                End If
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
                Me.Size = SystemInformation.WorkingArea.Size
                Me.Location = SystemInformation.WorkingArea.Location
                Exit Select
            Case FormWindowState.Minimized
                Me.WindowState = FormWindowState.Minimized
                Exit Select
            Case FormWindowState.Normal
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
                Me.Location = m_FormSizeAndLocation.Location
                Me.Size = m_FormSizeAndLocation.Size
                Exit Select
        End Select
        m_WindowState = p_NewState
    End Sub
 
    Private Sub ButtonMinimize_Click_1(sender As Object, e As EventArgs) Handles ButtonMinimize.Click
        ChangeWindowState(FormWindowState.Minimized)
    End Sub
 
    Private Sub ButtonMaximize_Click_1(sender As Object, e As EventArgs) Handles ButtonMaximize.Click
        If m_WindowState = FormWindowState.Maximized Then
            ChangeWindowState(FormWindowState.Normal)
            ButtonMaximize.Text = "Max"
        Else
            ChangeWindowState(FormWindowState.Maximized)
            ButtonMaximize.Text = "Res"
        End If
    End Sub
 
    Private Sub ButtonClose_Click(sender As Object, e As EventArgs)
        Close()
    End Sub
 
    Public Sub New()
        InitializeComponent()
        AddHandler panel1.MouseDown, AddressOf panel1_MouseDown
        AddHandler panel1.MouseMove, AddressOf panel1_MouseMove
        AddHandler panel1.MouseUp, AddressOf panel1_MouseUp
        AddHandler panel1.MouseDoubleClick, AddressOf panel1_MouseDoubleClick
 
    End Sub
    Private m_MousePressed As Boolean = False
    Private m_oldX As Integer, m_oldY As Integer
    Sub panel1_MouseDown(sender As Object, e As MouseEventArgs)
        Dim TS As Point = Me.PointToScreen(e.Location)
        m_oldX = TS.X
        m_oldY = TS.Y
        m_MousePressed = True
    End Sub
    Sub panel1_MouseUp(sender As Object, e As MouseEventArgs)
        m_MousePressed = False
    End Sub
    Sub panel1_MouseMove(sender As Object, e As MouseEventArgs)
        If m_MousePressed = True AndAlso m_WindowState <> FormWindowState.Maximized Then
            Dim TS As Point = Me.PointToScreen(e.Location)
            Me.Location = New Point(Me.Location.X + (TS.X - m_oldX), Me.Location.Y + (TS.Y - m_oldY))
            m_oldX = TS.X
            m_oldY = TS.Y
        End If
    End Sub
    Sub panel1_MouseDoubleClick(sender As Object, e As MouseEventArgs)
        ButtonMaximize_Click_1(ButtonMaximize, New EventArgs())
    End Sub
 
    Private Sub ButtonClose_Click_1(sender As Object, e As EventArgs) Handles ButtonClose.Click
        Close()
    End Sub
 
End Class

6   голосов, оценка 4.333 из 5


СОХРАНИТЬ ССЫЛКУ