0

我正在开发一个项目,其中某些表单将具有重复的填充组合框的方法。在下面的代码片段中,安装在给定 pc 上的字体作为项目添加到组合框中。如何传递一个实际要填充的组合框的参数?例如,AddFonts(组合框)

Private Sub AddFonts()
    'add the font names installed on this pc to the font name combo box
    ' Get the installed fonts collection.
    Dim allFonts As New InstalledFontCollection
    ' Get an array of the system's font familiies.
    Dim fontFamilies() As FontFamily = allFonts.Families

    ' Display the font families.
    For i As Integer = 0 To fontFamilies.Length - 1
        'figure our how to make the textbox passable as a paramter
        cbxTitleFonts.Items.Add(fontFamilies(i).Name)
    Next
End Sub
4

1 回答 1

0

将控件作为 Control Datatype 传递,并将其转换为函数中的实际控件。

Public  Sub mycallingfunc()
    myfunc(textbox1)
End Sub

Public Shared Sub myfunc(ctrl As Control)
    Dim txt As TextBox = DirectCast(ctrl, TextBox)
End Sub
于 2012-05-10T07:46:42.070 回答