2011-03-20 56 views

回答

2

有些事情你必须做,以使其正常工作。首先,等待OnLoad()方法运行是很重要的。你才知道窗户有多大。当用户以不同的DPI运行视频适配器时,它不会是另一台机器上的设计尺寸。您还必须删除边框和标题,当您为窗口设置形状时,它们不再适用。这会让你重新执行他们所做的工作。至少你想让用户仍然可以移动窗口。

样本形式做这个:

Public Class Form1 
    Public Sub New() 
     InitializeComponent() 
     Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 
     Me.DoubleBuffered = True 
    End Sub 

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) 
     '' Set window shape 
     Using path As New System.Drawing.Drawing2D.GraphicsPath 
      path.AddEllipse(0, 0, Me.ClientSize.Width, Me.ClientSize.Height) 
      Me.Region = New Region(path) 
     End Using 
     MyBase.OnLoad(e) 
    End Sub 

    Private Const WM_NCHITTEST As Integer = &H84 
    Private Const HTCLIENT As Integer = 1 
    Private Const HTCAPTION As Integer = 2 
    Private Const CaptionHeight As Integer = 30 

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) 
     MyBase.WndProc(m) 
     '' Detect clicks at top of window to allow it to be moved 
     If m.Msg = &H84 AndAlso m.Result.ToInt32() = HTCLIENT Then 
      Dim pos As Point = New Point(m.LParam.ToInt32()) 
      pos = Me.PointToClient(pos) 
      If pos.Y < CaptionHeight Then m.Result = CType(HTCAPTION, IntPtr) 
     End If 
    End Sub 

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) 
     '' Draw a simple caption 
     e.Graphics.FillRectangle(Brushes.Blue, 0, 0, Me.ClientSize.Width, CaptionHeight) 
     MyBase.OnPaint(e) 
    End Sub 
End Class 

以此为出发点,以实现自己的窗口镶边。您可能需要添加一个让用户关闭窗口的字形。 BackgroundImage属性是为窗口赋予“纹理”的好方法。或者修改OnPaint()来绘制自己的。

3

您可以设置表格的Region属性。

要创建一个圆形区域,请创建一个GraphicsPath,请致电AddEllipse,然后将其传递给构造函数Region

1

设置这些属性窗体

1. BackgroundImage = your_Image   ' image of shape you want 
2. BackColor  = Outside_Area_Color ' color of outside area of image 
3. FormBorderStyle = None     ' to hide border and TitleBar of form 
4. TransparentKey = Same_as_BackColor