我在设置MDI表单的语言时遇到问题。 在我的主要表单中,我有一个menustrip,我使用资源文件进行翻译
我想知道我做的是否正确
我的代码是这样的(示例):
Public Class Main
Public SNFrm As New SalesNote
Private Sub SetLanguage()
SNFrm.Text = My.Resources....
SNFrm.AcceptBtn.Text = My.Resources...
End Sub
Private Sub MenuSalesNote_Click(......)
SNFrm = New SalesNote
SNFrm.MdiParent = Me
SNFrm.StartPosition = FormStartPosition.CenterScreen
SNFrm.Show()
End Sub
End Class
然后,在My SalesNote Form_Closing Event
中Main.SNFrm.Dispose()
这是正确的吗?救命啊!
答案 0 :(得分:2)
确保您的IsMdiContainer
在您的媒体资源中设置为True
,否则您可以像编辑表单一样以编程方式设置它:
Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
End Sub
您无需立即为SalesNote表单创建实例:
Public SNFrm As SalesNote
因为你在这里实例化它:
Private Sub MenuSalesNote_Click(......)
SNFrm = New SalesNote
SNFrm.MdiParent = Me
SNFrm.StartPosition = FormStartPosition.CenterScreen
SNFrm.Show()
End Sub
但是,如果在SetLanguage()
之前调用MenuSalesNote_Click()
过程,那么立即实例化它是好的,或者你可以在这里实例化它:
Private Sub SetLanguage()
SNFrm = New SalesNote
SNFrm.Text = My.Resources....
SNFrm.AcceptBtn.Text = My.Resources...
End Sub
但是你不再在MenuSalesNote_Click()
中实例化它了:
Private Sub MenuSalesNote_Click(......)
SNFrm.MdiParent = Me
SNFrm.StartPosition = FormStartPosition.CenterScreen
SNFrm.Show()
End Sub
您还可以通过检查是否已存在SalesNote表单的实例来实现此目的:
Private Sub MenuSalesNote_Click(......)
If (SNFrm is Nothing) Then
SNFrm = New SalesNote
End if
SNFrm.MdiParent = Me
SNFrm.StartPosition = FormStartPosition.CenterScreen
SNFrm.Show()
End Sub
Private Sub SetLanguage()
If (SNFrm is Nothing) Then
SNFrm = New SalesNote
End if
SNFrm.Text = My.Resources....
SNFrm.AcceptBtn.Text = My.Resources...
End Sub