Wenn Ihr Plugin über Einstellungsmöglichkeiten verfügt, sollten Sie die vom CPS zur Verfügung gestellten Funktionen zum Verwalten nutzen.
Mit Copy-Discovery 20000 ist es möglich, Ihre eigenen Kategorien zu dem Optionen-Dialog vom Hauptprogramm hinzuzufügen.
Die Einstellungen lassen sich unkompliziert speichern und abrufen.
Um die dazu nötigen Funktionen zu nutzen, benötigen Sie eine Variable vom Typ: CD2000Plugin.Interfaces.CD2000
Die Funktionen befinden sich, in den Subinterfaces CD2000 und Other.
Praktisches Beispiel :: Schritt 1
Definieren Sie zwei globale Variablen vom Typ Integer und CD2000Plugin.Interfaces.CD2000
In der Integer-Variable wird die TabID welche von Copy-Discovery 2000 bestimmt wird, gespeichert.
Mit diesem Wert verwaltet Copy-Discovery 2000 alle hinzugefügten Optionskategorien.
Wichtig ist, dass die Integer-Variable als Shared definiert ist, da der Inhalt der Variable ansonsten verloren geht. CPS ist, wie immer, für die Kommunikation zwischen CD2000 Hauptprogramm und den Plugin verantwortlich.
Code:
C# Code
private static int Tab_ID; private CD2000Plugin.Interfaces.CD2000 CPS;
Visual Basic .NET Code
Private Shared Tab_ID As Integer Private CPS As CD2000Plugin.Interfaces.CD2000
Praktisches Beispiel :: Schritt 2
Die Function AddOptionsTab benötigt als Paramter eine TabPage, diese TabPage sollen Sie nun erzeugen. Auf meiner TabPage befinden sich eine CheckBox, ein Label und eine TextBox. Natürlich ist es
auch möglich, Events der einzelnen Controls zu verwalten (Siehe AddHandler).
Code:
Private Function CreateOptionsTab() As Windows.Forms.TabPage Dim tabDemo As New Windows.Forms.TabPage Dim chkDemo As New Windows.Forms.CheckBox Dim txtDemo As New Windows.Forms.TextBox Dim lblDemo As New Windows.Forms.Label
txtDemo.Name = "txtDemo"
txtDemo.Location = New Drawing.Point(16, 56)
txtDemo.Text = CPS.Other.GetSetting("OptionsDemo", "txtDemo") Return tabDemo End Function
Private Sub chkDemo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) If sender.Checked Then
sender.Parent.Controls(1).Visible = False
sender.Parent.Controls(2).Visible = False Else
sender.Parent.Controls(1).Visible = True
sender.Parent.Controls(2).Visible = True End If End Sub
Praktisches Beispiel :: Schritt 3
Das Speichern der Einstellungen übernimmt die Funktion SafeSetting, das Abrufen erfolgt über GetSetting.
Im folgenden Codeauszug speichere ich den CheckStatus der CheckBox und den Text des Eingabefeldes.
Code:
Private Sub SafeSettings() Dim tabDemo As Windows.Forms.TabPage = CPS.CD2000.GetOptionsTab(Tab_ID)
CPS.Other.SafeSetting("OptionsDemo", "chkDemo", CType(tabDemo.Controls(0), Windows.Forms.CheckBox).Checked)
CPS.Other.SafeSetting("OptionsDemo", "txtDemo", CType(tabDemo.Controls(2), Windows.Forms.TextBox).Text) End Sub
Praktisches Beispiel :: Schritt 4
Nun müssen wir die oben erstellten Funktionen nur noch in die einzelnen CD2000 Events einbinden.
Beim Starten vom Hauptprogramm wird die eigene TabPage zum TabControl des Optionen Dialogs hinzugefügt. Beim Starten des Optionen Dialogs
wird der Inhalt Ihrer TabPage aktualisiert,
indem Sie bei jedem Öffnen der Optionen eine neue TabPage erzeugen und mittels UpdateOptionsTab eine Aktualisierung vornehmen.
Beim Speichern der Optionen rufen wir die von uns erstellte Funktion SafeSettings auf.
Code:
Public Function Events(ByVal Message As CD2000Plugin.Interfaces.IPlugin.EnumMessages, ByVal Data As Object) As Boolean Implements CD2000Plugin.Interfaces.IPlugin.Events Select Case Message Case CD2000Plugin.Interfaces.IPlugin.EnumMessages. MainForm_OnCopyDiscovery2000Start Dim tabDemo As Windows.Forms.TabPage = CreateOptionsTab()
Tab_ID = CPS.CD2000.AddOptionsTab(tabDemo)
Case CD2000Plugin.Interfaces.IPlugin.EnumMessages.Options_Load Dim tabDemo As Windows.Forms.TabPage = CreateOptionsTab()
CPS.CD2000.UpdateOptionsTab(Tab_ID, tabDemo) Case CD2000Plugin.Interfaces.IPlugin.EnumMessages.Options_SafeSettings
SafeSettings() End Select End Function
Praktisches Beispiel :: Schritt 5
Zum Schluss wie immer in der Initialize Methode CPS mit dem Hauptprogramm verknüpfen.
Code:
C# Code
Nicht verfügbar
Visual Basic .NET Code
Public Sub Initialize(ByVal Host As CD2000Plugin.Interfaces.CD2000) Implements CD2000Plugin.Interfaces.IPlugin.Initialize
CPS = Host End Sub
Public Class clsUseOptionsDemoMain Implements CD2000Plugin.Interfaces.IPlugin Private Shared Tab_ID As Integer Private CPS As CD2000Plugin.Interfaces.CD2000
Public Function Events(ByVal Message As CD2000Plugin.Interfaces.IPlugin.EnumMessages, ByVal Data As Object) As Boolean Implements CD2000Plugin.Interfaces.IPlugin.Events Select Case Message Case CD2000Plugin.Interfaces.IPlugin.EnumMessages. MainForm_OnCopyDiscovery2000Start Dim tabDemo As Windows.Forms.TabPage = CreateOptionsTab()
Tab_ID = CPS.CD2000.AddOptionsTab(tabDemo)
Case CD2000Plugin.Interfaces.IPlugin.EnumMessages.Options_Load Dim tabDemo As Windows.Forms.TabPage = CreateOptionsTab()
CPS.CD2000.UpdateOptionsTab(Tab_ID, tabDemo) Case CD2000Plugin.Interfaces.IPlugin.EnumMessages.Options_SafeSettings
SafeSettings() End Select End Function
Private Sub SafeSettings() Dim tabDemo As Windows.Forms.TabPage = CPS.CD2000.GetOptionsTab(Tab_ID)
CPS.Other.SafeSetting("OptionsDemo", "chkDemo", CType(tabDemo.Controls(0), Windows.Forms.CheckBox).Checked)
CPS.Other.SafeSetting("OptionsDemo", "txtDemo", CType(tabDemo.Controls(2), Windows.Forms.TextBox).Text) End Sub
Private Function CreateOptionsTab() As Windows.Forms.TabPage Dim tabDemo As New Windows.Forms.TabPage Dim chkDemo As New Windows.Forms.CheckBox Dim txtDemo As New Windows.Forms.TextBox Dim lblDemo As New Windows.Forms.Label
txtDemo.Name = "txtDemo"
txtDemo.Location = New Drawing.Point(16, 56)
txtDemo.Text = CPS.Other.GetSetting("OptionsDemo", "txtDemo") Return tabDemo End Function
Private Sub chkDemo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) If sender.Checked Then
sender.Parent.Controls(1).Visible = False
sender.Parent.Controls(2).Visible = False Else
sender.Parent.Controls(1).Visible = True
sender.Parent.Controls(2).Visible = True End If End Sub
Public Sub Initialize(ByVal Host As CD2000Plugin.Interfaces.CD2000) Implements CD2000Plugin.Interfaces.IPlugin.Initialize
CPS = Host End Sub End Class