欧洲高福利的表现:在VB中用什么代码可以让登陆窗体为多边型或圆型,请告诉我,谢谢

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 13:16:35
我正在学用VB做管理系统,我想把登陆的界面做漂亮点,能给点建议及方法吗?谢谢

以下代码演示中间有一个洞的窗体
把它研究明白了你自然就会做其它各种图形的窗体了!
还是得多学习,不能总用现成的,对你有帮助!呵呵^_^
Private Sub Form_Resize()
Const RGN_DIFF = 4

Dim outer_rgn As Long
Dim inner_rgn As Long
Dim combined_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single

If WindowState = vbMinimized Then Exit Sub

' Create the regions.
wid = ScaleX(Width, vbTwips, vbPixels)
hgt = ScaleY(Height, vbTwips, vbPixels)
outer_rgn = CreateRectRgn(0, 0, wid, hgt)

border_width = (wid - ScaleWidth) / 2
title_height = hgt - border_width - ScaleHeight
inner_rgn = CreateEllipticRgn( _
border_width + ScaleWidth * 0.1, _
title_height + ScaleHeight * 0.1, _
ScaleWidth * 0.9, ScaleHeight * 0.9)

' Subtract the inner region from the outer.
combined_rgn = CreateRectRgn(0, 0, 0, 0)
CombineRgn combined_rgn, outer_rgn, _
inner_rgn, RGN_DIFF

' Restrict the window to the region.
SetWindowRgn hWnd, combined_rgn, True
End Sub

把登陆的界面做漂亮你可以用窗体特效,花式退出窗体等方法,举例来说:你试一试下面的代码:

代码一:

Private Sub Command1_Click()
GotoVal = Me.Height / 2

For Gointo = 1 To GotoVal
'NEW ADDITION NEXT LINE

DoEvents
Me.Height = Me.Height - 10
'Me.Top = (Screen.Height - Me.Height) \ 2
If Me.Height <= 11 Then GoTo horiz
Next Gointo

'This is the width part of the same sequence above
horiz:
Me.Height = 30
GotoVal = Me.Width / 2

For Gointo = 1 To GotoVal
'NEW ADDITION NEXT LINE

DoEvents
Me.Width = Me.Width - 10
'Me.Left = (Screen.Width - Me.Width) \ 2
If Me.Width <= 11 Then End
Next Gointo

End
End Sub
这是一个很简单的例子,再说一个复杂的!

代码二:

添加一个模块(代码如下):
Option Explicit

'****************************************************************
'*Author: Carl Slutter
'*
'*e-mail to hardwood@erols.com
'*
'*Description:
'*This module (a work in progress) currently either
'*explodes or implodes a form.
'*
'*The larger the "Movement" value the slower the
'*explosion or implosion. It is possible to have the form
'*explode/implode from various directions although this
'*code does not include that option.
'*
'* Call is ExplodeForm (or ImplodeForm) FormName, Movement

'*Creation Date: Thursday 23 January 1997 2:33 pm
'*Revision Date: Thursday 23 January 1997 2:33 pm
'*
'*Version Number: 1.10
'*
'*This code may be freely used by any individual in a personal
'*project. If the code is modified or additional effects are
'*added, I would appreciate receiving a copy of the revised
'*code.
'*However, if the code is used in a project developed
'*in the anticipation of a profit, permission of the author
'*must be obtained and a fee may be charged.
'****************************************************************

'Declarations

#If Win16 Then
Type RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
#Else
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
#End If

'User and GDI Functions for Explode/Implode to work

#If Win16 Then
Declare Sub GetWindowRect Lib "User" (ByVal hwnd As Integer, lpRect As RECT)
Declare Function GetDC Lib "User" (ByVal hwnd As Integer) As Integer
Declare Function ReleaseDC Lib "User" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Declare Sub SetBkColor Lib "GDI" (ByVal hdc As Integer, ByVal crColor As Long)
Declare Sub Rectangle Lib "GDI" (ByVal hdc As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer)
Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
Declare Function SelectObject Lib "GDI" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Declare Sub DeleteObject Lib "GDI" (ByVal hObject As Integer)
#Else
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function SelectObject Lib "user32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
#End If

'****************************************************************
'*Author: Carl Slutter
'*
'*Description:
'*The higher the "Movement", the slower the window
'*"explosion".
'*
'*Creation Date: Thursday 23 January 1997 2:27 pm
'*Revision Date: Thursday 23 January 1997 2:27 pm
'*
'*Version Number: 1.00
'****************************************************************

Sub ExplodeForm(f As Form, Movement As Integer)
Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long

GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)

For i = 1 To Movement
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i

X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)

End Sub

Public Sub ImplodeForm(f As Form, Direction As Integer, Movement As Integer, ModalState As Integer)
'****************************************************************
'*Author: Carl Slutter
'*
'*Description:
'*The larger the "Movement" value, the slower the "Implosion"
'*
'*Creation Date: Thursday 23 January 1997 2:42 pm
'*Revision Date: Thursday 23 January 1997 2:42 pm
'*
'*Version Number: 1.00
'****************************************************************

Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long

GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)

For i = Movement To 1 Step -1
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i

X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)

End Sub

再在Form1中使用如下代码:
Private Sub Command1_Click()
Call ImplodeForm(Me, 2, 500, 1)
End
Set Form1 = Nothing
End Sub

Private Sub Form_Load()
Call ExplodeForm(Me, 500)
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call ImplodeForm(Me, 2, 500, 1)
End Sub
这是爆破式窗体的代码!