我从右侧调整表单大小的代码可以正常工作,但实际上是非常糟糕或有很多延迟。当我调整大小时,我的所有图像都会模糊,我绘制的矩形会闪烁。一旦正常鼠标,一切正常。
我将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
答案 0 :(得分:0)
对于闪烁,表单不会将DoubleBuffered属性传递给其子控件,例如TableLayoutPanel。而是尝试向项目添加一个新类,它将doubleBuffer tableLayoutPanel。
Public Class DoubleBufferedTableLayoutPanel
Inherits TableLayoutPanel
Public Sub New()
Me.DoubleBuffered = True
End Sub
End Class
构建项目,新版本的TableLayoutPanel将作为DoubleBufferedTableLayoutPanel放在您的工具箱中。从那里开始就像使用代码中的TableLayoutPanel一样使用它。