在运行时更改窗体和usercontrol(.frm和.ctl)的字体

Kar*_*Rao 1 vb6 fonts user-controls controls

我有一个VB 6加载项,它将所有项目添加到项目组,遍历这些项目的每个组件,如果找到表单或用户控件,则更改其属性.

属性由用户定义.如果用户想要更改所有表单或usercontrol的高度,则代码段如下所示

Private Sub Update_ButtonClick()
  '..declaring all the variables here

  ' VBInstance is initialized to VBIDE.VBE when the add-in is loaded

  For Index = 1 To projCount
    compoCount = VBInstance.VBProjects(Index).VBComponents.Count
    For jIndex = 1 To compoCount

      csFileName = VBInstance.VBProjects(Index).VBComponents(jIndex).name
      componentType = VBInstance.VBProjects(Index).VBComponents(jIndex).Type

      If componentType = VBIDE.vbext_ct_VBForm Or componentType = VBIDE.vbext_ct_UserControl Then '.frm or .ctl         
        VBInstance.VBProjects(Index).VBComponents(jIndex).Properties(propChange).Value = propvalue 'changing the property
        VBInstance.VBProjects(Index).VBComponents(jIndex).SaveAs csFileName 'Saving the file
      End If
    Next jIndex
  Next Index
End Sub
Run Code Online (Sandbox Code Playgroud)

每当我给出属性名称时Font,我都会收到错误

运行时错误'425'无效的对象使用

我试图PropertyBag.WritePropertyhttp://visualbasic.freetutes.com/learn-vb6-advanced/lesson13/p20.html但它不会成为我的目的.

有没有办法设置Font控件或表单的属性?

当我在记事本中打开ctl或表单时,我找不到Font它中的属性,所以我不能在这里使用文本替换.

有人可以帮忙吗?

更新的代码:


Private Sub Update_ButtonClick()
    Dim fobject As New StdFont
    fobject.Name = "Arial"
    Set propvalue = fobject
    For Index = 1 To projCount
     compoCount = VBInstance.VBProjects(Index).VBComponents.Count
     For jIndex = 1 To compoCount
      csFileName = VBInstance.VBProjects(Index).VBComponents(jIndex).Name
      componentType = VBInstance.VBProjects(Index).VBComponents(jIndex).Type
      If componentType = 5 Or componentType = 8 Then 
       VBInstance.VBProjects(Index).VBComponents(jIndex).Properties("Font").Value=  propvalue
      VBInstance.VBProjects(Index).VBComponents(jIndex).SaveAs csFileName 
      End If
       Next jIndex
     Next Index 
End Sub
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是

Run-time error '425':
Invalid object use
Run Code Online (Sandbox Code Playgroud)

Dea*_*nna 5

Font属性是一个对象,而不是简单的内在价值.您需要使用分配给Set的适当StdFont对象propvalue.

或者,您可以使用特殊情况设置字体,并将属性的.Name属性设置为所需的字体名称.