久久―日本道色综合久久,亚洲欧美精品在线,狼狼色丁香久久婷婷综合五月,香蕉人人超,日本网站黄,国产在线观看不卡免费高清,无遮挡的毛片免费

2023信創(chuàng)獨(dú)角獸企業(yè)100強(qiáng)
全世界各行各業(yè)聯(lián)合起來(lái),internet一定要實(shí)現(xiàn)!

VB編程之路-如何讓界面美化

2004-03-01 eNet&Ciweek


  可能各位看關(guān)玩過石器時(shí)代,一定會(huì)對(duì)里面的TextBox的效果感到很爽,VB還不是可以做到,有焦點(diǎn)的控件可以使用SetFocus方法來(lái)為其設(shè)置焦點(diǎn),可是一個(gè)窗體上如果控件太多了,一個(gè)一個(gè)的用SetFocus是不是太傻了?這一節(jié)的主角就是--------API函數(shù),

首先聲明:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
但是這里的SetFocus會(huì)和控件的SetFocus會(huì)搞混淆,改改吧,
Private Declare Function nSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
只要Alias指向的接口是對(duì)的前面的函數(shù)名稱簡(jiǎn)直就是擺設(shè),
在建立一個(gè)過程:
Public Function sSetFocus() As Long
Dim CPos As POINTAPI,Successfull As Boolean,hWnd As Long
DoEvents
Successfull =GetCursorPos(CPos)
If Not Successfull Then Exit Sub ’如果未成功則退出該過程
hWnd=WindowFromPoint(CPos.x,CPos.y)
sSetFocus=nSetFocus(hWnd)
End Sub
  在窗體上放一個(gè)Timer控件,Interval 屬性設(shè)為100,就是0.1秒,在Timer1控件的Timer事件中填入sSetFocus,在運(yùn)行一下看看,效果怎么樣?

  可是有的先生小姐要問了,TextBox難道就不能用ScrollBar嗎?非也非也,選 工程->部件->Microsoft Windows Common Controls-2 6.0 (SP3)就是你的答案,至于卷動(dòng)TextBox就去研究SendMessage函數(shù)吧,否則又有騙稿費(fèi)之嫌,如果想作綠色軟件,不想用控件,可以用俺前面講到的Label控件,利用字體 Webdings 來(lái)模擬ScrollBar,需要注意的是,如果模擬ScrollBar,上下左右箭頭分別是5,6,3,4,別忘了把字體設(shè)為Webdings

  再來(lái)講講窗體的美化,其實(shí)將BorderStyle屬性設(shè)為0就是很好的2D美化;)可是,這樣一來(lái),問題又來(lái)了,怎么辦?凡事都要請(qǐng)API來(lái)幫忙,這里需要兩個(gè)API,一下是該API的聲明:

Public Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long 注釋:這個(gè)API是用來(lái)解下鼠標(biāo)的追蹤器,關(guān)于他的過多用法以及詳細(xì)介紹可以寫信向俺咨詢,
還有
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long’這個(gè)該不要俺多介紹了吧
Public Const HTCAPTION = 2 ’代表窗體的標(biāo)題區(qū)
Public Const WM_NCLBUTTONDOWN = &HA1 ’表示非工作區(qū)左鍵按下
  原理很簡(jiǎn)單,卸下鼠標(biāo)追蹤器后向Form發(fā)送一個(gè)移動(dòng)窗體的消息,其實(shí)做到這一點(diǎn)的方法很多,但俺個(gè)人認(rèn)為這一種最簡(jiǎn)單,添加一個(gè)過程:

Public Sub MoveForm(hWnd As Long)
DoEvents
ReleaseCapture
SendMessage hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
在Form的MouseMove事件中:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button=vbLeftButton Then MoveForm hWnd’如果按下鼠標(biāo)左鍵就移動(dòng)窗體
End Sub
臺(tái)下的這位小姐又納悶了,可是光禿禿的窗體沒有了標(biāo)題欄也不好看,俺要向這為小姐推薦俺的東東-ActiveX控件,ToolSign,需要的人可以寫信給俺聯(lián)系,
該控件需要在代碼編輯區(qū)域內(nèi)添加一下代碼:
’一下聲明是用在ToolSign的 AutoQuit屬性的
Public Const EXIT_FORCE = 2 ’注意,在VB中運(yùn)行的時(shí)候如果選用此退出方式,VB也會(huì)退出
Public Const EXIT_MESSAGE = 1 ’由操作系統(tǒng)發(fā)送關(guān)閉消息
Public Const EXIT_CUSTOM = Not (EXIT_FORCE Or EXIT_MESSAGE) ’自定義
將其注冊(cè)后在部件欄中把e-Dogkid Studio Tools Sign打鉤,添加到工具箱中,雙擊加入到窗體中,
在Form的Load事件中添加一下初始化代碼:
Private Sub Form_Load()
With Sign1
.AutoQuit = EXIT_CUSTOM
.ParentsHWND = hWnd ’填了此屬性可以直接用ToolSign來(lái)移動(dòng)窗體而不需要前面的代碼
End With
End Sub
Sign1的Click事件
Private Sub Sign1_Click()
End ’關(guān)閉程序
End Sub
在Form的Resize事件中添加一下代碼:
Private Sub Form_Resize()
Sign1.Width = Width
End Sub
如果想讓窗體可以改變大小,可以修改一下屬性
Caption ""
BorderStyle 2或5
ControlBox False

  不知道各位看關(guān)見過爆炸試的窗體沒有?,沒有見過可以從俺要另外一個(gè)俺自己的ActiveX DLL,我的那個(gè)東東其實(shí)是給我的Software作運(yùn)行庫(kù)的,各位若不嫌棄,可以用用,注冊(cè)后在工程->引用->e-Dogkid Runtime Library
然后在窗體Load事件中輸入:
Private Sub Form_Load()
Dim System As e_Dogkid_Runtime_Library.System
Set System = New e_Dogkid_Runtime_Library.System
Show
System.BoomIt hDC, 60, Width, Height, Left, Top
Set System = Nothing
End Sub

相關(guān)頻道: eNews

您對(duì)本文或本站有任何意見,請(qǐng)?jiān)谙路教峤唬x謝!

投稿信箱:tougao@enet16.com