将控件放在vb.net中的表单边框上?

时间:2013-07-22 18:25:42

标签: vb.net forms user-interface vb.net-2010 formborderstyle

当formborderstyle设置为formborderstyle.sizable

时,我有一个项目,我希望将控件放在窗体的边框上

Formborderstyle.none将无效,因为它无法在运行时调整大小,并在最大化时位于任务栏前面。

我正在使用vb.net 2010。

1 个答案:

答案 0 :(得分:1)

我不确定你是否可以覆盖边框的绘图,如果你不确定如何将控制添加到边框。

您可以在最大化表单之前临时更改边框样式。 并且您可以重载客户端事件以自己处理重新调整表单的大小。

您是否还有其他原因不想使用Formborderstyle.none

Public Class Form1
Inherits Windows.Forms.Form

Private Const BorderWidth As Integer = 30 'This is just for demo purposes.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Panel1.Location = New Point(Me.Width - BorderWidth, 0)
    Panel1.Width = BorderWidth
End Sub

Public xLocation, yLocation As Integer

Private Sub Panel1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
    xLocation = PointToScreen(Cursor.Position).X
    yLocation = PointToScreen(Cursor.Position).Y
End Sub

Private Sub Panel1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
    'Stop resizing form
    Me.Width = Me.Width + (PointToScreen(Cursor.Position).X - xLocation)
    xLocation = PointToScreen(Cursor.Position).X
    yLocation = PointToScreen(Cursor.Position).Y
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    Me.WindowState = FormWindowState.Maximized
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub

End Class