Несколько дочерних MDI-клиентов, которые зависят от my.settings
У меня есть несколько клиентов, и я хочу, чтобы каждая настройка клиента зависела от my.settings.
У меня есть этот код:
'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
, это делает мой интерфейс, чтобы стать таким
Я использовал это так
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
1 ответ
Решение
Это:
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
должно быть так:
Public Class frmClient
Private ReadOnly host As String
Private ReadOnly port As Integer
Private WithEvents client As MessageClient
Public Sub New(parameterForIP As String, parameterForPort As Integer)
InitializeComponent()
host = parameterForIP
port = parameterForPort
client = New MessageClient(host, port)
End Sub
'And lots and lots of code
End Class