新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 开发语言 > VB教程 > 正文:Visual Basic开发要点三则

Visual Basic开发要点三则

新客网 XKER.COM 2007-01-31 来源: 收藏本文
   

  一、 用控件拖放表单

  ---- 怎样用控件拖放表单呢?很简单,将这段代码插入到Declare部分。

  Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

  再在控制的Mousedown事件中插入:

  Sub Command1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Ret&
ReleaseCapture
Ret& = SendMessage(Me.hWnd, &H112, &HF012, 0)
End Sub

  二、 把表单放在屏幕的正中央

  ---- 在开发VB程序时,一般希望将表单放在屏幕可利用区域的正中央,实现上可以利用Move(Screen.Width - Width)\2,(Screen.Height - Height)\2的方法来实现。但是当用户使用Windows 95或 NT 操作系统时,在 屏幕底端会有一任务条,上述的实现方法并未考虑该任务条所占的空间,表单实际并未处于屏幕可利用区域的正中央。下面的代码段实现了在每次启动应用程序时,无论屏幕是否有任务条,表单都会屏幕可利用区域的正中央。在工程中增添一模块,在模块中加上如下的代码:

  Option Explicit
Private Const SPI_GETWORKAREA = 48
Private Declare Function SystemParametersInfo& Lib "User32" Alias
"SystemParametersInfoA" (ByVal uAction As Long,ByVal uParam As Long, lpvParam As
Any, ByVal fuWinIni As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Function CenterForm32 (frm As Form)
Dim ScreenWidth&, ScreenHeight&, ScreenLeft&, ScreenTop&
Dim DesktopArea As RECT
Call SystemParametersInfo (SPI_GETWORKAREA, 0, DesktopArea, 0)
ScreenHeight = (DesktopArea.Bottom - DesktopArea.Top) * Screen.TwipsPerPixelY
ScreenWidth = (DesktopArea.Right - DesktopArea.Left) * Screen.TwipsPerPixelX
ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX
ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY
frm.Move (ScreenWidth - frm.Width)\ 2 + ScreenLeft, (ScreenHeight - frm.Height) \ 2
+ ScreenTop
d Function

[责任编辑:editor]

共2页: 上一页 [1] [2] 下一页
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐