【发布时间】:2017-01-28 10:35:19
【问题描述】:
我使用 vb .net 创建了一个小的无边框表单。该表单包含三个方形按钮。表格的大小为 (93, 31)。在表单的设计过程中一切都很好,但是当我运行程序时,表单的大小会增加到有点像(98,34)。我什至在表单的 autosize 属性的 true 和 false 之间切换,以检查它是否是问题的原因,但这有帮助。
如何阻止表单调整大小?
编辑:
我通过将表单的 FormBorderStyle 属性设置为 None 使表单无边框
这是代码
Public Class OSD_Dialog
Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer
' The folllowing three subs are helpfull in making the form dragable
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
drag = True
mousex = Windows.Forms.Cursor.Position.X - Me.Left
mousey = Windows.Forms.Cursor.Position.Y - Me.Top
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If drag Then
Me.Top = Windows.Forms.Cursor.Position.Y - mousey
Me.Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = False
End Sub
'The following sub is helpful in creating an outline on the border of the form
Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
MyBase.OnPaintBackground(e)
Dim rect As New Rectangle(0, 0, Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
e.Graphics.DrawRectangle(Pens.White, rect)
End Sub
Private Sub OSD_Dialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TopMost = True
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Red
TransparencyKey = BackColor
End Sub
【问题讨论】:
-
你能添加一些代码让我们看看吗?
-
您是如何设置表单无边框的(您设置了哪些属性)?
-
@S.Serp 我通过将表单的 FormBorderStyle 属性设置为 None 使表单无边框