函数不能声明为Form Class的成员

时间:2016-12-03 14:44:05

标签: vb.net winforms textbox console

我正在使用文本框实现一个伪控制台。编译器抛出以下错误:'GetUserInputLine'不是'Form1'的成员。 我不知道为什么这行'TempString = myForm.GetUserString()'会抛出此错误。

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Public Class Form1
    Inherits Form

    Dim WithEvents textBox1 As TextBox
    Dim UserString As String

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub InitializeComponent()

        Me.textBox1 = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        ' 
        ' textBox1
        ' 
        Me.textBox1.AcceptsReturn = True
        Me.textBox1.AcceptsTab = True
        Me.textBox1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.textBox1.Multiline = True
        Me.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        ' 
        ' Form1
        ' 
        Me.ClientSize = New System.Drawing.Size(284, 264)
        Me.Controls.Add(Me.textBox1)
        Me.Text = "PseudoGUIConsole Example"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

Private Sub textBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles textBox1.KeyDown
Dim LastLine() As String


    If e.KeyCode = Keys.Enter Then
        LastLine = Split(textBox1.Text, vbCrLf)

        If LastLine(Ubound(LastLine)) = "" Then
            Exit Sub    'Do Nothing
        Else    
            UserString = LastLine(Ubound(LastLine))
        End If

        e.Handled = True
        textBox1.Focus()
    End If
End Sub

Private Sub PrintLine(ByVal UserText As String)
    textBox1.AppendText(vbCrLf & UserText)
End Sub

Private Function GetUserInputLine() As String
    GetUserInputLine = UserString
End Function


<STAThreadAttribute()> _
    Public Shared Sub Main()

    Dim myForm As New Form1()
    Dim TempString As String

    myForm.PrintLine("Enter a String?") 'Prompt and 
    TempString = myForm.GetUserString() 'wait for the input
    myForm.PrintLine("You Entered:: " & TempString)

Application.Run( myForm )

    End Sub


End Class

0 个答案:

没有答案