|
一、用控件拖放表单 ----怎样用控件拖放表单呢?很简单,将这段代码插入到Declare部分。 DeclareFunctionReleaseCaptureLib"user32"()AsLong DeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLong 再在控制的Mousedown事件中插入: SubCommand1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle) DimRet& ReleaseCapture Ret&=SendMessage(Me.hWnd,&H112,&HF012,0) EndSub
二、把表单放在屏幕的正中央 ----在开发VB程序时,一般希望将表单放在屏幕可利用区域的正中央,实现上可以利用Move(Screen.Width-Width)\2,(Screen.Height-Height)\2的方法来实现。但是当用户使用Windows95或NT操作系统时,在屏幕的底端会有一任务条,上述的实现方法并未考虑该任务条所占的空间,表单实际并未处于屏幕可利用区域的正中央。下面的代码段实现了在每次启动应用程序时,无论屏幕是否有任务条,表单都会处于屏幕可利用区域的正中央。在工程中增添一模块,在模块中加上如下的代码: OptionExplicit PrivateConstSPI_GETWORKAREA=48 PrivateDeclareFunctionSystemParametersInfo&Lib"User32"Alias"SystemParametersInfoA"(ByValuActionAsLong,ByValuParamAsLong,lpvParamAsAny,ByValfuWinIniAsLong) PrivateTypeRECT LeftAsLong TopAsLong RightAsLong BottomAsLong EndType
PublicFunctionCenterForm32(frmAsForm) DimScreenWidth&,ScreenHeight&,ScreenLeft&,ScreenTop& DimDesktopAreaAsRECT CallSystemParametersInfo(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 EndFunction
----要调用CenterForm32函数,可在表单的Load事件中增添代码CenterForm32Me即可。以上代码在VB4/32,VB5中实现。
三、在RichTextBox控件中实现上、下标形式 ----VB提供了一个优秀的控件RichTextBox,我们可以在其中实现文本的各种编辑方式。下面的程序是在RichTextBox控件中实现上标和下标的形式,主要是使作为上、下标的字符的尺寸小一些,位置在基线上下浮动。程序利用属性SelCharOffset,由它确定RichTextBox控件中的文本是出现在基线上(正常状态),当SelCharOffset>0时,文本出现在基线之上,成为上标形式; ----当SelCharOffset<0时,文本出现在基线之下,成为下标形式。
----该属性在设计时无效。
----在表单的Load事件中添加以下代码:
PrivateSubForm_Load() RichTextBox1.Font.Name="TimesNewRoman" RichTextBox1.Font.Size=10 RichTextBox1.Text="H2SO4" 'Movethenumbersdown2points. OffsetRichTextRichTextBox1,1,1,2 OffsetRichTextRichTextBox1,4,1,-2 EndSub
PrivateSubOffsetRichText(boxAsRichTextBox,startAsInteger,lengthAsInteger,offsetAsInteger) '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 EndSub 该程序在VB4/32和VB5上调试通过。最后在RichTextBox 控件中字符串的形式为:H2SO4.->
|
| |
|