调整无边界表格的大小是有问题的

Resize Bordless Form is Glitchy

我从右侧调整表单大小的代码有效,但确实有问题或有很多滞后。当我调整大小时,我所有的图像都模糊了,我绘制的矩形也闪烁了。一切正常,但是一旦 mouseup.

我将formborderstyle 从无边框设置为可调整大小,并且表单可以正常调整大小。

希望有人能指出我的代码有什么问题。

Dim myresize As Boolean = False
Dim cursorx As Integer
Dim cursory As Integer

Private Sub TableLayoutPanel1_MouseDown(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseDown

    If e.Location.X > Me.Width - 7 And e.Location.Y > 11 And e.Location.Y < Me.Height - 10 Then
        myresize = True
        cursorx = Windows.Forms.Cursor.Position.X - Me.Width
        cursory = Windows.Forms.Cursor.Position.Y - Me.Height
    End If

End Sub

Private Sub TableLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseMove

    If myresize = True Then
        Me.Width = Windows.Forms.Cursor.Position.X - cursorx
    End If

End Sub

Private Sub TableLayoutPanel1_MouseUp(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseUp

    myresize = False

End Sub

对于闪烁,表单不会将 DoubleBuffered 属性 传递给它的子控件,例如您的 TableLayoutPanel。相反,请尝试向您的项目添加一个新的 class,这将使 tableLayoutPanel 加倍缓冲。

Public Class DoubleBufferedTableLayoutPanel
    Inherits TableLayoutPanel
    Public Sub New()
        Me.DoubleBuffered = True
    End Sub
End Class

构建您的项目,新版本的 TableLayoutPanel 将在您的工具箱中作为 DoubleBufferedTableLayoutPanel。从那里就像在代码中使用 TableLayoutPanel 一样使用它。