vb.net textbox.text没有更新

时间:2017-04-27 14:34:34

标签: vb.net

在使用VB的VS2015中,我有一个winform,它使用另一个winform(从类中实例化)作为消息显示,以显示表中一系列行的当前状态。当我第一次更新消息显示并显示它时,文本框显示消息,但后续更新文本框的调用无法显示(我允许在首次启动表单时设置textbox.text,但此处不使用该选项)。我已经在调试器中跟踪了该操作,并且在MessageText的set方法中正确更新了txtStatus.text属性 - 它只是不显示。奇怪的是,如果我将文本框的.tabstop设置为false,则文本框根本不显示任何数据。第二个(可能是相关的)问题是我在消息表单上还有一个按钮,该按钮根本无法显示(显示屏显示按钮所在的白色框)。按钮没什么异常,我只设置了.text属性。就好像我已经创建了MssgClass的多个实例并且我正在更新错误的实例,但据我所知,我只实例化了一个实例。

我已经查看了有关此问题的所有文档和问题,但尚未找到解决方案。

这是调用表单的代码:

Public Class myform

.
.
Dim oMessage As New MssgClass("")
For nIndex As Integer = 0 To oDataSet.Tables(0).Rows.Count - 1
    .
    .
    oMessage.MessageText = "My Message"
    oMessage.Show()
    .
    ' index this table - MyIndex is a com object MyIndex.dll
    iIndexed = MyIndex.IndexFile("the table name")
    '

Next
oMessage.close()

结束班

这里是MssgClass的代码:(包含一个名为txtStatus的文本框)

Public Class MssgClass

Public Property MessageText() As String
    Get
        Return Me.txtStatus.Text
    End Get
    Set(ByVal pcMssg As String)
        Me.txtStatus.Text = pcMssg
        Me.txtStatus.Show()
    End Set
End Property

Public Sub New(ByVal pcMssg As String)
    InitializeComponent()
    Me.txtStatus.Text = pcMssg
End Sub

结束班

MssgClass表单设置为FixedDialog的bordertyle, controlbox是假的(我不想要用户可以操作的任何控件而不是我提供的按钮),最重要的是真的。这是InitializeComponent方法:

Private Sub InitializeComponent()

Me.txtStatus = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'txtStatus
'
Me.txtStatus.BackColor = System.Drawing.SystemColors.Control
Me.txtStatus.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.txtStatus.Font = New System.Drawing.Font("Arial", 12.0!, 
   System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 
   CType(0, Byte))
Me.txtStatus.Location = New System.Drawing.Point(25, 22)
Me.txtStatus.Multiline = True
Me.txtStatus.Name = "txtStatus"
Me.txtStatus.Size = New System.Drawing.Size(414, 20)
Me.txtStatus.TabIndex = 0
Me.txtStatus.Text = "Textbox"
Me.txtStatus.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("Arial", 12.0!, 
    System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 
    CType(0, Byte))
Me.Button1.Location = New System.Drawing.Point(174, 59)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(118, 35)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Cancel"
Me.Button1.UseVisualStyleBackColor = True
'
'MssgClass
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(474, 115)
Me.ControlBox = False
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.txtStatus)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "MssgClass"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.TopMost = True
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub

我假设我在MssgClass中做了一些事情(或者没有做某事),我只是不知道是什么。任何帮助将不胜感激!

0 个答案:

没有答案