简体   繁体   English

在vb6中替换表单控件

[英]Replacing form controls in vb6

We have an in house button control, and quite frankly it sucks. 我们有一个内部按钮控制,坦白说它很糟糕。 I'd like to replace it but I don't want to go onto every form in our project and delete/add a new control. 我想替换它,但我不想在我们的项目中使用每个表单并删除/添加新控件。 It seems to me that if I design a new button that has all the same properties as the old one then I ought to be able to give it the same name as the old one and just replace all the reference lines in the vbp files to point to the new control. 在我看来,如果我设计一个新的按钮,它具有与旧的相同的属性,那么我应该能够给它与旧的相同的名称,只需将vbp文件中的所有参考行替换为点到新的控制。

Has anyone tried this (better yet have you heard of a tool that will do it for you) and if so what 'gotchas' should I be on the look out for? 有没有人试过这个(更好的是你听说过一个能为你做的工具)如果是这样的话,我应该注意什么?

Thanks! 谢谢!

The *.vbp files are one place you'll need to change. * .vbp文件是您需要更改的位置。 There are also references to the used control libraries in the files containing GUIs -- that's form (*.frm), control (*.ctl), and property page (*.pag) files. 在包含GUI的文件中也引用了所使用的控件库 - 即形式(* .frm),控件(* .ctl)和属性页(* .pag)文件。 These files are in a plain text format and you can see the references at the top. 这些文件采用纯文本格式,您可以在顶部看到引用。 They look like this: 它们看起来像这样:

Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"

Those refs will need to be added or updated in all relevant files if the new control is a compiled OCX. 如果新控件是已编译的OCX,则需要在所有相关文件中添加或更新这些引用。 If it's in the same project I don't think it needs any reference there, and if it's in a different project in the same project group I'm not sure. 如果它在同一个项目中我不认为它需要任何参考,如果它在同一个项目组中的另一个项目中,我不确定。 Save a test form with the new control to see. 使用新控件保存测试表单以查看。

Note that you don't have to keep the same control class name. 请注意,您不必保持相同的控件类名称。 Inside the *.frm/ctl/pag files, instances of individual controls on them are represented by a simple format like this: 在* .frm / ctl / pag文件中,它们上的各个控件的实例由一个简单的格式表示,如下所示:

Begin VB.CommandButton Command2 
   Caption         =   "Cancel"
   Height          =   375
   Left            =   2460
   TabIndex        =   1
   Top             =   2400
   Width           =   1455
End

The syntax of the first line there is "Begin LibraryOrProjectName.ClassName NameOfThisInstance". 第一行的语法是“Begin LibraryOrProjectName.ClassName NameOfThisInstance”。 So, provided the offending control's name is distinctive it should be easy to search & replace references to it both in the BASIC source and in the GUI layouts. 因此,如果违规控件的名称与众不同,则应该很容易在BASIC源和GUI布局中搜索和替换对它的引用。 You might want a plain text editor that can perform search and replace across multiple files (Notepad++ is one). 您可能需要一个纯文本编辑器,可以跨多个文件执行搜索和替换(Notepad ++是一个)。

Some control properties are stored like this: 某些控件属性存储如下:

   Picture         =   "frmMain.frx":292F

These correspond to the *.frx, *.ctx, and *.pgx files, which contain binary data for the values of certain control properties. 这些文件对应于* .frx,* .ctx和* .pgx文件,这些文件包含某些控件属性值的二进制数据。 I don't think these files should need altering or cause any problems. 我不认为这些文件需要改变或导致任何问题。 They don't appear to contain control names. 它们似乎不包含控件名称。

Use a full compile (Ctrl+F5) to be sure no problems linger in parts of the source afterward. 使用完整编译(Ctrl + F5)以确保之后在源的部分中没有问题。

Never tried it. 没试过。 Good luck. 祝好运。

There is only one tip to be added to the accepted answer. 在接受的答案中只添加了一个提示。

If you need to replace any generic VB control with 3rd party or custom ActiveX control you must replace the: 如果您需要使用第三方或自定义ActiveX控件替换任何通用 VB控件,则必须替换:

BeginProperty Font

with

BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}

Omiting to do so results with run-time error 713 when trying to edit/open the form. 在尝试编辑/打开表单时,忽略运行时错误713会导致这样做。

If there is no BeginProperty statement in the block then control uses default font and this replacement is not needed. 如果块中没有BeginProperty语句,则控件使用默认字体,并且不需要此替换。

An additional scenario to look for is if the classes in the OCX are referenced directly in code. 要查找的另一个方案是OCX中的类是否直接在代码中引用。

In other words, if the control class was ABCButton then you need to look for ABCButton in all .BAS and .CLS files as well, and make appropriate changes. 换句话说,如果控件类是ABCButton那么你需要在所有.BAS.CLS文件中查找ABCButton ,并进行适当的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM