现在位置:站长资讯->首页->软件编程
Visual Basic开发要点三则_
时间:2006-9-3 21:13:06 来源: 作者: 编辑: 【关闭

b>一、 用控件" 拖放表单

---- 怎样用控件拖放表单呢?很简单,将这段代码插入到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



---- 要调用CenterForm32" 函数,可在表单的" Load事件中增添代码CenterForm32 Me即可。以上代码" 在VB4/32,VB5 中实现。

三、 在RichTextBox 控件中实现上、" 下标形式

---- VB提供了一个优秀的控件RichTextBox,我们可以在其中实现文本的各种编辑方式。下面的程序是在RichTextBox 控件中实现上标和下标的形式,主要是使作为上、下标的字符的尺寸小一些,位置在基线上下浮动。程序利用属性SelCharOffset,由它确定RichTextBox 控件中的文本是出现在基线上(正常状态),当SelCharOffset $#@62;0 时,文本出现在基线之上,成为上标形式;

---- 当SelCharOffset$#@60; 0 时,文本出现在基线之下,成为下标形式。

---- 该属性在设计时无效。

---- 在表单的Load事件中添加以下代码:

Private Sub Form_Load()
RichTextBox1." Font.Name = "Times New Roman"
RichTextBox1.Font.Size = 10
RichTextBox1." Text = "H2SO4"
" Move the numbers " down 2 points.
OffsetRichText RichTextBox1, 1, 1, 2
OffsetRichText RichTextBox1, 4, 1, -2
End Sub

Private Sub OffsetRichText(box As RichTextBox, start As Integer, length As Integer,
offset As Integer)

"box指RichTextBox控件;start指作为上下标的
"字符的起始位置;length指上下标字符的长度;
"offset指上标还是下标,大于0上标;小于0下标。

box.SelStart = start
box.SelLength = length
box.SelFontSize = box.Font.Size -" abs(offset)
box.SelCharOffset = ScaleY(offset,vbPoints, vbTwips)
box.SelStart = 0
box.SelLength = 0
End Sub

上述程序在" WINDOWS98/ME中通过。


发表评论 相关信息
用户:
查看评论
留言:
验证码:
* 请各位网友遵纪守法并注意语言文明。
*《互联网电子公告服务管理规定》
*《全国人大常委会关于维护互联网安全的规定》
 行业新闻
 服务器
 数据库
版权 © 佰网 www.hb666.com 所有 综合门户站点    未经许可不得复制或镜像  
招商热线:0710 -3851666  3858555  售后服务:0710-3422031  传真:0710- 3452881
  佰网数据:0710-3178666   合作 Email:admin@hb666.com   销售Email:666@hb666.com
CEO信箱  客户留言  我要投诉  诚聘英才