[英]Unable to update ToolStrip using class file
Here is a simple example of what I am doing in the real application 这是我在实际应用程序中正在做的简单示例
FORM CONTAINING MAIN SUB OpenNew.vb 包含主订阅表OpenNew.vb
Step 1 - Main prompts user for input using dialog in same file (OpenNew.vb) Step 2 - Users Selects What type of Project they are opening, Type 1 or Type 2 Step 3 - strOpenNewResponse is populated when OpenNew dialog is closed Step 3 - Form is opened based on selection 步骤1-Main提示用户使用同一文件中的对话框输入内容(OpenNew.vb)。步骤2-用户选择他们要打开的项目类型,类型1或类型2步骤3-关闭OpenNew对话框时,将填充strOpenNewResponse步骤3-根据选择打开表格
Public Class OpenNew
Public Shared strOpenNewResponse As String = Nothing
Public Shared Sub Main()
OpenNew.ShowDialog()
If strOpenNewResponse IsNot Nothing Then
Dim formToShow As Form = Nothing
Select Case strOpenNewResponse
Case "Type1"
formToShow = New Form1
formToShow.ShowDialog()
Case "Type2"
formToShow = New Form2
formToShow.ShowDialog()
End Select
End If
End Sub
End Class
Form1 would have a StatusBar with one ToolStrip and a TreeView: Form1将具有一个带有一个ToolStrip和一个TreeView的StatusBar:
Public Class Form1
Inherits Form
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Utilities.DisplayStatus("Loading, Please Wait...")
Me.Cursor = Cursors.WaitCursor
PopulateTreeView("Root Node")
Utilities.DisplayStatus("Process Complete")
Me.Cursor = Cursors.Default
End Sub
End Class
Then the Class file is named Utilities.vb 然后将Class文件命名为Utilities.vb
Public Class Utilities
Public Shared Sub DisplayStatus(ByVal strStatusMessage As String)
Form1.toolstripDisplayStatus.Text = strStatusMessage
Form1.toolstripDisplayStatus.Visible = True
Form1.statusstripParent.Refresh()
End Sub
End Class
When I do this the ToolStrip Item never updates. 当我这样做时,ToolStrip项永远不会更新。 It just stays the default value.
它只是保留默认值。
Of Course if I run it this way (without the class) 当然,如果我这样运行(不上课)
Public Class Form1
Inherits Form
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Me.Cursor = Cursors.WaitCursor
toolstripDisplayStatus.Text = "Loading, Please Wait..."
toolstripDisplayStatus.Visible = True
statusstripParent.Refresh()
PopulateTreeView("Root Node")
toolstripDisplayStatus.Text = "Process Complete"
toolstripDisplayStatus.Visible = True
statusstripParent.Refresh()
Me.Cursor = Cursors.Default
End Sub
End Class
I thought it might be a problem with some sort of Public/Private conflict but I still can't seem to figure it out. 我认为这可能是某种公共/私人冲突的问题,但我似乎仍然无法弄清楚。
I might just be blinded by the obvious at this point 在这一点上,我可能只是被显而易见的事物所蒙蔽
Can anyone give me an idea what might be causing this? 谁能告诉我这可能是什么原因造成的?
ADDED A SCREENSHOT for soohoonigan 已为soohoonigan添加了SCREENSHOT
formToShow = Form1
will work (remove the New) formToShow = Form1
将起作用(删除新的)
Your Utilities class is referencing Form1 directly, but you have just an instance of that. 您的Utilities类直接引用Form1,但是您只有一个实例。 Alternatively, if you need multiple instances of Form1 you could pass in the form to the Sub like this:
或者,如果您需要Form1的多个实例,则可以将表单传递给Sub,如下所示:
Public Shared Sub DisplayStatus(ByVal temp As Form1, ByVal strStatusMessage As String)
temp.toolstripDisplayStatus.Text = strStatusMessage
temp.toolstripDisplayStatus.Visible = True
temp.statusstripparent.Refresh()
End Sub
and call it like such: 并这样称呼它:
Utilities.DisplayStatus(Me, "Loading, Please Wait...")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.