VB窗体的设计技巧
#1?牐犚弧⒋唇ú还嬖虼翱?
?牐犚唇ú还嬖虼翱诳瓷先ニ坪鹾苣选5绻颐撬涤眉感写刖涂梢允迪郑馑坪醪豢伤家椤?墒率稻褪侨绱耍in32 API有很多让你意想不到的功能,大家不妨试一试:
#2?牐?1.菱形窗口
?牐燩rivate Declare Function CreatePolygonRgn Lib “gdi32” (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
?牐燩rivate Declare Function SetWindowRgn Lib “user32” (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
?牐燩rivate Type POINTAPI
?牐爔 As Long
?牐爕 As Long
?牐燛nd Type
?牐燩rivate Sub Form_Load?煟?
?牐燚im ap(4) As POINTAPI
?牐燚im hx As Integer
?牐燚im hy As Integer
?牐燚im reRgn As Integer
?牐爃y = Me.Height \(2 * Screen.TwipsPerPixelY)
?牐爃x = Me.Width \(2 * Screen.TwipsPerPixelX)
?牐牐?设置Polygon为一个以Form1为依据的菱形
?牐燼p(0).x = 0: ap(0).y = hy
?牐燼p(1).x = hx: ap(1).y = 0
?牐燼p(2).x = Me.Width \ Screen.TwipsPerPixelX: ap(2).y = hy
?牐燼p(3).x = hx: ap(3).y = Me.Height \ Screen.TwipsPerPixelY
?牐燼p(4) = ap(0)??
?牐爎eRgn = CreatePolygonRgn(ap(0), 5, 1)
?牐牐?设置窗口为菱形
?牐燬etWindowRgn Me.hWnd, reRgn, True
?牐燛nd Sub
#2?牐?2.椭圆形窗口
?牐燩rivate Declare Function CreateEllipticRgn Lib “gdi32” (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long,ByVal Y2 As Long) As Long
?牐燩rivate Declare Function SetWindowRgn Lib “user32” (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
?牐燩rivate Sub Form_Load()
?牐燬how
?牐燬etWindowRgn hWnd,CreateEllipticRgn(0,0,300,200),true
?牐燛nd Sub
#1?牐牰⒋唇ㄗ中痛疤?
?牐燩rivate Declare Function BeginPath Lib “gdi32” (ByVal hdc As Long) As Long
?牐燩rivate Declare Function TextOut Lib “gdi32” Alias “TextOutA” (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
?牐燩rivate Declare Function EndPath Lib “gdi32” (ByVal hdc As Long) As Long
?牐燩rivate Declare Function PathToRegion Lib “gdi32” (ByVal hdc As Long) As Long
?牐燩rivate Declare Function DeleteObject Lib “gdi32” (ByVal hObject As Long) As Long
?牐燩rivate Declare Function SetWindowRgn Lib “user32” (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
?牐燩rivate Sub Form_Load()
?牐燚im hRgn As Long
?牐燤e.Height = 5265
?牐燤e.Left = 0
?牐燤e.Top = 0
?牐燤e.Width = 10200
?牐燱ith Me
?牐?.BackColor = QBColor(3)
?牐?.Font.Name = “隶书”
?牐?.Font.Size = 250
?牐燛nd With
?牐牐г诖疤迳喜按疤濉弊致肪?
?牐燘eginPath Form1.hdc
?牐燭extOut Form1.hdc, 0, 0, “窗体”, 6
?牐燛ndPath Form1.hdc
?牐牐Ы穆肪蹲晃?
?牐爃Rgn = PathToRegion(hdc)
?牐牐?设置窗体形状为转换成的区域
?牐燬etWindowRgn hwnd, hRgn. 1
?牐牐?删除对象,释放系统资源
?牐燚eleteObject hRgn
?牐燛nd Sub
#1?牐犎⒋唇ㄒ桓霰尘熬哂薪ケ湫Ч拇疤?
?牐犘矶郬indows应用程序的安装界面都是一个颜色由蓝至黑的渐变背景,下面的示例就是在VB中实现窗体背景的渐变效果。
?牐燩rivate Sub Gradient(TheObject As Object,Redval, Greenval, Blueval)
?牐燚im Step, i,T,L, R, B
?牐燬tep = (TheObject.Height / 60)
?牐燭 = 0
?牐燣 = 0
?牐燫 = TheObject.Width
?牐燘 =T +Step
?牐牐?使用循环在窗体上从上至下依次绘制60个矩形
?牐燜or i = 1 To 60
?牐燭heObject.Line (l, t)-(r, b), RGB(Redval, Greenval, Blueval), BF
?牐燫edval = Redval - 4
?牐燝reenval = Greenval - 4
?牐燘lueval =Blueval - 4
?牐營f Redval <= 0 Then Redval = 0
?牐營f Greenval <= 0 Then Greenval = 0
?牐營f Blueval <= 0 Then Blueval = 0
?牐燭 = B
?牐燘 = B +Step
?牐燦ext
?牐燛nd Sub
?牐燩rivate Sub Form_Resize?煟?
?牐燝radient Form1, 0, 0, 255
?牐燛nd Sub
#1?牐犓摹⑹勾疤迨贾毡3衷谧钌喜?
?牐犛惺庇τ贸绦蛐枰桓鲂畔⒒虿檠疤遄鼙3衷谧钌喜悖词骨谢坏狡渌疤逡材芸醇么疤澹馐峭ü饔肳indows API函数SetWindowPos()实现的,示例如下:
?牐爋ption Explicit
?牐燩rivate Declare Function SetWindowPos Lib “user32”(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
?牐燙onst HWND_TOPMOST=-1
?牐燙onst SWP_SHOWWINDOW=&&H40
?牐燩rivate sub Form_load()
?牐燚im retValue as long
?牐燫etvalue=setwindowpos(me.hwnd,hwnd_topmost,me.currentx,me.currenty,300,300,
?牐爏wp_showwindow)
?牐燛nd sub
#1?牐犖濉⑹勾疤逡缘鼻胺直媛嗜料允?
?牐犜谟τ贸绦虻谋嘀频魇怨讨校逼聊环直媛矢谋涫保疤蹇赡懿荒苷O允荆馐笨梢栽诖疤宓腖oad事件中插入系列代码,即可使窗体启动时以当前屏幕分辨率全屏显示:
?牐燩rivate Sub Form_Load()
?牐燜orm1.Top = 0 '设置窗体上边界位置
?牐燜orm1.Left = 0 '设置窗体左边界位置
?牐燜orm1.Width = Screen.Width '设置窗体宽度为屏幕宽度
?牐燜orm1.Height = Screen.Height '设置窗体高度为屏幕高度
?牐燛nd Sub