您的位置:首页 > 编程语言 > VB

VB6 Add-Ins 自动添加控件前缀

2005-10-10 13:07 337 查看
以前在开发的过程中,总是制定一个命名规范,然后在使用中总是反复的查看手册,真是麻烦,今天我在给一个兄弟展示一个新作的VB6外接程序的时候,他就说能不能自动添加控件前缀,这样就不用死记硬背了,所以试验了一下,还好,挺简单的,主要代码如下:

Public WithEvents CtlHandler As VBControlsEvents

'监控控件名称前缀
Private Sub WatchNamePrefixion(ByVal VBControl As VBIDE.VBControl)
Dim FileContent As String
FileContent = ReadAll(App.Path & "\ControlPrefixion.config")
FileContent = Replace(FileContent, " ", "")
Dim Rows() As String
Dim Cols() As String
Dim i As Integer
Dim ii As Integer
Rows = Split(FileContent, vbCrLf)
For i = LBound(Rows) To UBound(Rows)
Cols = Split(Rows(i), "=")
If UBound(Cols) = 1 Then
If UCase(VBA.TypeName(VBControl.ControlObject)) = UCase(Cols(0)) Then
If UCase(VBA.Left(VBControl.Properties("Name"), Len(Cols(1)))) <> UCase(Cols(1)) Then
VBControl.Properties("Name") = Cols(1) & VBControl.Properties("Name")
End If
Exit For
End If
End If
Next
Erase Rows
Erase Cols
End Sub

Private Sub CtlHandler_ItemRenamed(ByVal VBControl As VBIDE.VBControl, ByVal OldName As String, ByVal OldIndex As Long)
WatchNamePrefixion VBControl
End Sub
在这段代码中,主要是建立一个VB6 的外接程序,然后在ItemRenamed事件中,增加前缀就行了。

控件的前缀列表放到了ControlPrefixion.config文件中,如下:

3DPanel=pnl
ADOData=ado
Animatedbutton=ani
Checkbox=chk
Combobox=cbo
drop-downlistbox=cbo
Commandbutton=cmd
Commondialog=dlg
Communications=com
Data=dat
Data-boundcombobox=dbcbo
Data-boundgrid=dbgrd
Data-boundlistbox=dblst
Datacombo=dbc
Datagrid=dgd
Datalist=dbl
Datarepeater=drp
Datepicker=dtp
Directorylistbox=dir
Drivelistbox=drv
Filelistbox=fil
Flatscrollbar=fsb
Form=frm
Frame=fra
Gauge=gau
Graph=gra
Grid=grd
Hierarchicalflexgrid=flex
Horizontalscrollbar=hsb
Image=img
Imagecombo=imgcbo
ImageList=ils
Label=lbl
Lightweightcheckbox=lwchk
Lightweightcombobox=lwcbo
Lightweightcommandbutton=lwcmd
Lightweightframe=lwfra
Lightweighthorizontalscrollbar=lwhsb
Lightweightlistbox=lwlst
Lightweightoptionbutton=lwopt
Lightweighttextbox=lwtxt
Lightweightverticalscrollbar=lwvsb
Line=lin
Listbox=lst
ListView=lvw
MAPImessage=mpm
MAPIsession=mps
MCI=mci
Menu=mnu
Monthview=mvw
MSChart=ch
MSFlexgrid=msg
MSTab=mst
OLEcontainer=ole
Optionbutton=opt
Picturebox=pic
Pictureclip=clp
ProgressBar=prg
RemoteData=rd
RichTextBox=rtf
Shape=shp
Slider=sld
Spin=spn
StatusBar=sta
SysInfo=sys
TabStrip=tab
Textbox=txt
Timer=tmr
Toolbar=tlb
TreeView=tre
UpDown=upd
Verticalscrollbar=vsb

一旦加载了这个插件,当在窗体上增加了一个控件后,比如一个Command后,当在属性窗口中将名称改为“OK”后,系统自动增加“cmd”在控件名称前边,变成“cmdOK”,这样再也不用记住控件的前缀了。

有了这个,兄弟很高兴,至少可以将手册变得薄一点了。

在开发这个插件过程中,有点需要注意,就是一个公司总是有各种规范来规定程序员的代码开发规范,其实如果能够提供一些自动工具或者模板工具的话,程序员就不需要死记硬背了,所有的规范程序员也就自动遵守了,也就没有烦恼了,这样才是最好的办法,项目经理也就轻松了,^_^。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐