Da ich Herkunft und Verwendung Deiner CAD-Daten nicht kenne,
habe ich eine simple Klasse ohne Datenbindung erstellt, die ParameterInfos
aufnehmen und ggf. auch passende Controls auf einem
gegebenen Container (z.B. Win.Form) erstellen kann.
Instanzen dieser Klasse können in einer generischen Liste verwaltet werden.
Die Organisation des Event-Handling der dynamisch erstellten Controls
wäre zu diskutieren!
Public Class ParameterInfo
Public Enum ParamType
[Double]
Text
TextArray
DoubleArray
End Enum
Public Enum ControlType
TextBox
Combobox
ListBox
Button
End Enum
Dim _param_name As String
Public ReadOnly Property Param_Name As String
Get
Return _param_name
End Get
End Property
Dim _param_type As ParamType
Public ReadOnly Property Param_type As ParamType
Get
Return _param_type
End Get
End Property
Public Property Param_Value As Object 'einer der Parametertypen
Dim _control_type As ControlType
Dim _control_location As Point
Dim _control_size As Size
'Position und Größe des zugeordneten Labels
'Diese Angaben könnten auch relativ zu den entsprechenden
'Control-Eigenschaften berechnet werden.
Dim _label_location As Point
Dim _label_size As Size
''' <param name="Param_Name">eindeutiger Name des Parameters
''' (=Text im Label, Name des Control)</param>
''' <param name="Param_Type">Datentyp des Parameters</param>
''' <param name="Param_Value">Wert des Parameters
''' (wird im Control angezeigt)</param>
''' <param name="Control_Type">Typ des Control</param>
''' <param name="Control_Location">Position des Control auf dem Container
''' (gegeben in CreateControl)</param>
''' <param name="Control_Size">Größe des Control (Pixel)</param>
''' <param name="Label_Location">Position des Label,
''' das dem Control zugeordnet ist</param>
Public Sub New _
(Param_Name As String, Param_Type As ParamType, _
Param_Value As Object, _
Control_Type As ControlType, _
Control_Location As Point, Control_Size As Size, _
Label_Location As Point, Label_Size As Size)
_param_name = Param_Name
_param_type = Param_Type
_Param_Value = Param_Value
_control_type = Control_Type
_control_location = Control_Location
_control_size = Control_Size
_label_location = Label_Location
_label_size = Label_Size
End Sub
Public Function CreateControl(ByVal f As Control) As Control
'f ist der Container, in dem die Controls erstellt werden
Dim ctl As Control = Nothing
'Label zum Control erstellen und positionieren
Dim lbl As New Label With _
{.Parent = f, _
.Location = _label_location, .Size = _label_size, _
.Text = _param_name, .AutoSize = False}
'Control erstellen und aktuellen Value eintragen
Select Case _control_type
Case ControlType.Button
ctl = New Button With _
{.Text = GetValue(0).ToString}
Case ControlType.TextBox
ctl = New TextBox With _
{.Text = GetValue(0).ToString}
Case ControlType.Combobox
Dim cbo As New ComboBox
cbo.Items.AddRange(GetValue())
ctl = cbo
Case ControlType.ListBox
Dim lbo As New ListBox
lbo.Items.AddRange(GetValue)
ctl = lbo
End Select
If ctl IsNot Nothing Then
'allgemeine Control-Eigenschaften
With ctl
.Parent = f
.Name = _param_name
.Location = _control_location
.Size = _control_size
End With
End If
Return ctl
End Function
Private Function GetValue() As Object()
'Cast der Parameter-Value-Typen
Dim items() As Object = Nothing
If TypeOf _Param_Value Is Double() Then
Dim dbl As Double() = CType(_Param_Value, Double())
ReDim items(dbl.Length - 1)
For i As Integer = 0 To dbl.Length - 1
items(i) = dbl(i)
Next i
ElseIf TypeOf _Param_Value Is String() Then
Dim str As String() = CType(_Param_Value, String())
ReDim items(str.Length - 1)
For i As Integer = 0 To str.Length - 1
items(i) = str(i)
Next i
Else
ReDim items(0)
items(0) = _Param_Value
End If
Return items
End Function
End Class |