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

コントロールをコントロールデータ型として渡し、関数の実際のコントロールにキャストします。

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 に答える