tips_6 面向VisualBasic程序员的杂志 第6版.docx
《tips_6 面向VisualBasic程序员的杂志 第6版.docx》由会员分享,可在线阅读,更多相关《tips_6 面向VisualBasic程序员的杂志 第6版.docx(56页珍藏版)》请在优知文库上搜索。
1、WE1.COMETOTHESIXTHEDITIONOFTHEVBPJTECHNICA1.TIPSSUPP1.EMENT!ThesetipsandtricksweresubmittedbyprofessionaldevelopersusingVisualBasic3.0,VisualBasic4.0,VisualBasic5.0,VisualBasicforApplications(VBA),andVisualBasicScript(VBS).VB416/321.evel:IntermediateUSEBOO1.EANVARIAB1.ESFORCHECK-BOXVA1.UESVisualBasi
2、cspecifiesaBooleansdefaultvaluesaszeroforFalseand-1forTrue.Youmaysaveandsetthevalueofacheckbox,basedontheabsolutevalueofaBooleanvariable,asthesecorrespondtotheintrinsicconstantsVbUncheckedandVbChecked:DimbBoolasBooleanbBool=True/IfbBool=0thecheckboxwillbe/unchecked,ifitisanythingelseitwill,/bechecke
3、d.Checkl.Value=Abs(bBool)-JeremyBoschen,Branchburg,NewJerseyVB416/321.evel:IntermediateDISP1.AYHORIZONTA1.SCRO1.1.BARUnliketheWindows95commoncontrols,thestandardlistboxdoesnthaveahorizontalscrollbarwhenlistitemsaretoowidetofitwithinthelistbox.Fortunately,itsnothardtodirectalist-boxcontroltodisplayah
4、orizontalscrollbar.Addthiscodetoaforms1.oadevent.Itfillsalistboxwith100longstringsandcallsSetHScroIItoshowahorizontalscrollbarinthelistbox:PrivateSubForm_1.oad()DimiAsIntegerFori=1To1001.istl.AddItemCStr(i)&_ubottle(三)ofbeeronthewall.uNextiSetHScrollMe,1.istl,1.istl.1.ist(0)EndSubAddthiscode,whichin
5、cludestherequiredAPIdeclarationsandtheSetHScroIIroutine,toaBASmodule.TheSetHScroIIroutineusestheSendMessageAPIfunctiontosendthe1.B_SETHORIZONTA1.EXTENTmessagetoalistbox.Thelastargumentisanitemfromthelist,preferablyoneofthelongestitems.SetHScroIIdeterminesthestringswidthinpixelsandpassesthisvaluetoth
6、elistboxalongwiththe1.B_SETHORIZONTA1.EXTENTmessage.Thelistboxsetsitshorizontalextenttothisvalue,andifitiswiderthanthelist-boxcontrol,thelistboxdisplaysahorizontalscrollbar:#IfWin32ThenDeclareFunctionSendMessage1.ib11user3211_AliasnSendMessageAn(_ByValhwndAs1.ong,ByValwMsgAs1.ong,ByValwParamAs1.ong,
7、IParamAs1.ong)As1.ong#ElseDeclareFunctionSendMessage1.ib,user3211_AliasSendMessageAn(_ByValhwndAsInteger,ByValwMsgAsInteger,ByValwParamAsInteger,IParamAs1.ong)As1.ong#EndIf,Defineconstantformessagetolist-boxcontrolConst1.B_SETHORIZONTA1.EXTENT=&H194PublicSubSetHScroll(FrmAsForm,CtrlAs_Control,StrTex
8、tAsString)DimnScaleModeAsIntegerDimnTextWidthAsInteger,ScaleinpixelsforwindowmessagenScaleMode=Frm.ScaleModeFrm-ScaleMode=3,Getthewidth,inpixels,ofthetextstringnTextWidth=Frm.TextWidth(StrText),SendamessagetothelistboxSendMessageCtrl.hwnd,1.B_SETHORIZONTA1.EXTENT,nTextWidth,O,Restorepreviousscalemod
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- tips_6 面向VisualBasic程序员的杂志 第6版 面向 VisualBasic 程序员 杂志