0
我有一个多客户端,我得到here,我想要的是使客户端的每个设置依赖于my.settings。取决于my.settings的多个MDI子客户端
我有这样的代码:
'Sub to create client
Private Sub AddNewClient()
Call New frmClient() With {.MdiParent = Me}.Show()
End Sub
'OnLoad Event that creates the new client
Private Sub MainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Display a single client window by default.
Me.AddNewClient()
Me.AddNewClient()
End Sub
Public Class frmClient
Private ReadOnly host As String = Environment.MachineName
Private ReadOnly port As Integer = 3131
Private WithEvents client As New MessageClient(host, port)
'And lots and lots of code
End Class
我希望它是这样的:
'Sub to create client
Private Sub AddNewClient(parameterForIP, parameterForPort)
Call New frmClient(parameterForIP, parameterForPort) With {.MdiParent = Me}.Show()
End Sub
'OnLoad Event that creates the new client
Private Sub MainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Display a single client window by default.
Me.AddNewClient(my.settings.ipClient1, my.settings.ipPort1)
Me.AddNewClient(my.settings.ipClient2, my.settings.ipPort2)
End Sub
Public Class frmClient(parameterForIP, parameterForPort)
Private ReadOnly host As String = parameterForIP
Private ReadOnly port As Integer = parameterForPort
Private WithEvents client As New MessageClient(host, port)
'And lots and lots of code
End Class
'Lots of code follows here
看来,我失去了一些东西,我是谁?
更新:此基础上通过jmcilhinney
给出的代码,它使我的UI变得像我已经使用了这样的
Public Sub AddNewClient(clientIP As String, clientPort As Integer)
Call New frmClient(clientIP, clientPort) With {.MdiParent = Me}.Show()
End Sub
Private Sub MainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Display a single client window by default.
With My.Settings
Me.AddNewClient(.ipClient1, .portClient1)
Me.AddNewClient(.ipClient2, .portClient2)
End With
End Sub
非常感谢你的先生,请看我最新的问题。应用您的代码后,我的用户界面变空了。先生,你有什么想法吗? –
我错过了对'InitializeComponent'的必要调用。我已经相应地更新了代码。 – jmcilhinney
非常感谢你的先生! :d –