创建一个类,所以我可以在我的应用程序的任何地方调用

时间:2014-04-15 17:59:16

标签: vb.net

我为我的解决方案找到了非常有用的代码,但它是为表单设计的。 问题是: 如何从任何形式调用它?

以下是代码:


    Private ArabicInput As InputLanguage
    Private EnglishInput As InputLanguage
    PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    ' Set the default as the current Inputlanguage
    ArabicInput = InputLanguage.CurrentInputLanguage
    EnglishInput = InputLanguage.CurrentInputLanguage
    'Iterate to find the available Arabic and English Keyboards
    Dim count As Integer
    count = InputLanguage.InstalledInputLanguages.Count
    For i As Integer = 1 To (count - 1)
    If InputLanguage.InstalledInputLanguages(i).LayoutName.Contains("Arabic") = True Then
    'Found an Arabic Keyboard  
    ArabicInput = InputLanguage.InstalledInputLanguages(i)
    Else
    If InputLanguage.InstalledInputLanguages(i).LayoutName.Contains("English") = True Then
    'Found an English Keyboard 
    EnglishInput = InputLanguage.InstalledInputLanguages(i)
    End If
    End If
    Next  i
    End Sub

    Private Sub TextBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
    InputLanguage.CurrentInputLanguage = ArabicInput
    End Sub
    Private Sub TextBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
    InputLanguage.CurrentInputLanguage = EnglishInput
    End Sub

我的意思是如何从FORM2,Form3,等等调用它。

2 个答案:

答案 0 :(得分:0)

您可以创建一个类并将其编译为.dll文件。然后,您可以将.dll文件添加为表单项目,网页或控制台应用程序的参考。

答案 1 :(得分:0)

创建一个新模块(ProjectAdd Module),项目中的表单可以访问该模块中的代码。