1

我在将语言设置为 MDI 表单时遇到问题。在我的主要形式中,我有一个菜单条,我使用资源文件进行翻译

我想知道我是否做对了

我的代码是这样的(示例):

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()

这是正确的吗?帮助!

4

1 回答 1

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
于 2013-11-09T03:31:41.910 回答