是的,这是一个非常糟糕的问题,可能是任何一半体面的VB.NET程序员应该知道的问题。好吧,我是VB.NET的新手,所以我需要一些帮助。
我已经在另一个创建了一个Windows窗体类,其代码如下:
Imports System.Windows.Forms
Public Class Form2
Protected m_BlankValid As Boolean = True
Protected m_ReturnText As String = ""
Public Overloads Function ShowDialog( _
ByVal TitleText As String, _
ByVal PromptText As String, _
ByVal DefaultText As String, _
ByRef EnteredText As String, _
ByVal BlankValid As Boolean) As System.Windows.Forms.DialogResult
m_BlankValid = BlankValid
Me.PromptLabel.Text = PromptText
Me.Text = TitleText
Me.Txt_TextEntry.Text = DefaultText
Me.ShowDialog()
EnteredText = m_ReturnText
Return Me.DialogResult
End Function
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.Txt_TextEntry.Text = "" Then
Me.OK_Btn.Enabled = m_BlankValid
Else
Me.OK_Btn.Enabled = True
End If
End Sub
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.OK
m_ReturnText = Me.Txt_TextEntry.Text
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
m_ReturnText = ""
Me.Close()
End Sub
End Class
显然,我的设计上有一些图形。
要打电话给我的课,我想使用以下代码:
Dim TextReturned As String = ""
Dim a As New InputBox
If a.ShowDialog("The Title", "The Prompt", "Default", TextReturned, False) = Windows.Forms.DialogResult.Cancel Then
' Cancel Pressed
Beep()
Else
'
End If
我的错误是未定义Type“InputBox”。我怎样才能使它被定义?
谢谢,
Odinulf
答案 0 :(得分:2)
假设您的代码是从实际代码中复制/粘贴的,那么您的类名为Form2
而不是InputBox
。将自定义表单上的类声明更改为Public Class InputBox
如果你上面的片段只是有拼写错误,那可能会改变一些事情。
答案 1 :(得分:1)
您的代码为:
Dim a As New InputBox
但该类定义为:
Public Class Form2
意思是您的代码应该是:
Dim as New Form2()
注意:您也可以将您的课程重命名为:
Public Class Form2
到
Public Class InputBox
答案 2 :(得分:0)
好吧,根据您发布的代码,您的“InputBox”称为Form2(类名)。将其更改为InputBox,它应该可以工作。
答案 3 :(得分:-1)
InputBox
不是类型或类,它是一种方法。例如......
InputBox("The Title", "The prompt") 'and any other parameters you need