希望做一个椭圆型的窗体,用了以下方法
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    Dim rtn As Long
    BorderStyler = 0
    rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
    rtn = rtn Or WS_EX_LAYERED
    SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, RGB(252, 3, 21), 0, LWA_COLORKEY 结果无论怎么弄,都无法去掉窗体的边框。请高手指教了。

解决方案 »

  1.   

    BorderStyle 属性
    返回或设置对象的边框样式。对 Form 对象和 Textbox 控件在运行时是只读的
    设计时将窗体的BorderStyle属性设为0
      

  2.   

    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Sub Command1_Click()
    Dim ret As Long, w, h
    Me.ScaleMode = 3
    w = Me.ScaleWidth: h = Me.ScaleHeight
    ret = CreateEllipticRgn(0, 0, w, h)
    SetWindowRgn hWnd, ret, True
    DeleteObject ret
    End Sub
    设计时将窗体的BorderStyle属性设为0
      

  3.   

    tmd007的方法厉害,不过可能我没说清楚。窗体的形状其实是一个圆角的方形,所以不能简单地设成圆形。我现在把四个角去掉以后,就露出了窗体的边框了。
      

  4.   

    同样,设计时将窗体的BorderStyle设为0Option ExplicitPrivate Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Sub Form_Load()
        Dim Rgn As Long
        
        Dim r As Long       
        
        Me.ScaleMode = vbPixels
        
        r = 20  ' 圆角大小
        Rgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, r, r)
        SetWindowRgn hWnd, Rgn, True
        DeleteObject Rgn
    End Sub
      

  5.   

    在程序运行时修改窗体的BorderStyle也是可以的
    如果窗体没有菜单栏,只要先修改BorderStyle再设置一下窗体的caption就可以了。
    如果有菜单栏就麻烦一点。
      

  6.   

    就是的,创建圆角矩形 CreateRoundRectRgn