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”,这样再也不用记住控件的前缀了。
有了这个,兄弟很高兴,至少可以将手册变得薄一点了。
在开发这个插件过程中,有点需要注意,就是一个公司总是有各种规范来规定程序员的代码开发规范,其实如果能够提供一些自动工具或者模板工具的话,程序员就不需要死记硬背了,所有的规范程序员也就自动遵守了,也就没有烦恼了,这样才是最好的办法,项目经理也就轻松了,^_^。
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”,这样再也不用记住控件的前缀了。
有了这个,兄弟很高兴,至少可以将手册变得薄一点了。
在开发这个插件过程中,有点需要注意,就是一个公司总是有各种规范来规定程序员的代码开发规范,其实如果能够提供一些自动工具或者模板工具的话,程序员就不需要死记硬背了,所有的规范程序员也就自动遵守了,也就没有烦恼了,这样才是最好的办法,项目经理也就轻松了,^_^。
相关文章推荐
- VB6 Add-Ins 控件样式模板
- Flex中如何给DataGrid控件的项目添加一个可编辑TextArea/TextInput,单击控件内的项目时,自动进入编辑状态
- 为DataList控件添加自动编号的功能
- Javascript实现自动添加控件
- 关于Ajax控件ModalPopupExtender出现的 未通过 Sys.UI.DomEvent.addHandler 方法添加处理程序的解决方法。
- VB6 安装完成,添加Windows Common Controls 6.0控件,报错Object Library Not Registered
- 在WIN7 环境里PB里面添加控件OLE,选择insertcontrol选项卡就会报错自动关闭解决办法
- Visual Studio 2008 Designer.cs不能更新/自动添加控件声明的解决办法
- asp.net multiview控件如何自动添加view
- 自动添加控件,一次提交多条记录。
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
- 四二、js操作DOM(dom)改变css3属性时封装方法使自动识别浏览器添加css3属性前缀
- xml中搭建布局,当添加控件的时候自动生成的<Button android:layout_width="" android:layout_height="" />变成一行了
- 在VS2005和2008的对话框里,添加了一个MSCOMM通信控件,怎么mscomm.h和mscomm.cpp没有自动出现?
- 在Div中自动添加控件
- 章鱼哥—VB.NET 如何实现代码自动生成控件 添加绑定事件
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
- GridView后台自动添加行、列,行列不固定,并且再列里面添加服务器控件,然后取值
- 为Kindeditor控件添加图片自动上传功能