дла редактирования настроек программы использую PropertyGrid, который отображаю на отдельной форме
- Код: Выделить всё
Public Class frmSettings
Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
grdSettings.SelectedObject = My.Settings
End Sub
Private Sub frmSettings_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
My.Settings.Save()
End Sub
End Class
В сгенерированном студией классе дописал некоторые аттрибуты к свойствам, которые определяют коментарии и группу для свойства, а также написал пару классов, чтобы пользователь мог выбирать имя файла или путь через диалоговое окно
- Код: Выделить всё
Public Class clsFileNameEditor
Inherits Global.System.Drawing.Design.UITypeEditor
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Global.System.Drawing.Design.UITypeEditorEditStyle
Return Global.System.Drawing.Design.UITypeEditorEditStyle.Modal
End Function
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim f As New OpenFileDialog()
f.Filter = "Access File(*.mdb)|*.mdb"
f.ShowDialog()
Return f.FileName
End Function
End Class
Public Class clsPathEditor
Inherits Global.System.Drawing.Design.UITypeEditor
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Global.System.Drawing.Design.UITypeEditorEditStyle
Return Global.System.Drawing.Design.UITypeEditorEditStyle.Modal
End Function
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim f As New FolderBrowserDialog()
f.ShowDialog()
Return f.SelectedPath
End Function
End Class
Это сгенерированный студией класс
- Код: Выделить всё
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.1378
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings),MySettings)
#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
<Global.System.ComponentModel.CategoryAttribute("Application"), _
Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.ConnectionString), _
Global.System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""D:\MyProjects\MAIL ID\Mailing1\Mail" & _
"ing.mdb""")> _
Public ReadOnly Property MailingConnectionString() As String
Get
Return CType(Me("MailingConnectionString"), String)
End Get
End Property
<Global.System.ComponentModel.CategoryAttribute("User"), _
Global.System.ComponentModel.DescriptionAttribute("Map waar Excel bestanden zich bevinden."), _
Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute(""), _
Global.System.ComponentModel.EditorAttribute(GetType(clsPathEditor), GetType(System.Drawing.Design.UITypeEditor))> _
Public Property DirectoryExcelFiles() As String
Get
Return CType(Me("DirectoryExcelFiles"), String)
End Get
Set(ByVal value As String)
Me("DirectoryExcelFiles") = value
End Set
End Property
<Global.System.ComponentModel.CategoryAttribute("User"), _
Global.System.ComponentModel.DescriptionAttribute("Map waar Mailing Request bestanden zich bevinden."), _
Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute(""), _
Global.System.ComponentModel.EditorAttribute(GetType(clsPathEditor), GetType(System.Drawing.Design.UITypeEditor))> _
Public Property DirectoryRequestFiles() As String
Get
Return CType(Me("DirectoryRequestFiles"), String)
End Get
Set(ByVal value As String)
Me("DirectoryRequestFiles") = value
End Set
End Property
<Global.System.ComponentModel.CategoryAttribute("Application"), _
Global.System.ComponentModel.DescriptionAttribute("AccountID die U van de Post hebt gekregen."), _
Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("")> _
Public Property AccountID() As String
Get
Return CType(Me("AccountID"), String)
End Get
Set(ByVal value As String)
Me("AccountID") = value
End Set
End Property
<Global.System.ComponentModel.CategoryAttribute("Contact Persoon"), _
Global.System.ComponentModel.DescriptionAttribute("E-mail adres van de contactpersoon dat zal naar de Post gegeven worden. Dit is noodzakelijke informatie."), _
Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("")> _
Public Property Email() As String
Get
Return CType(Me("Email"), String)
End Get
Set(ByVal value As String)
Me("Email") = value
End Set
End Property
<Global.System.ComponentModel.CategoryAttribute("Application"), _
Global.System.ComponentModel.DescriptionAttribute("Naam van database bestand die zal gebruikt worden in dit programma."), _
Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute(""), _
Global.System.ComponentModel.EditorAttribute(GetType(clsFileNameEditor), GetType(System.Drawing.Design.UITypeEditor))> _
Public Property DataBase() As String
Get
Return CType(Me("DataBase"), String)
End Get
Set(ByVal value As String)
Me("DataBase") = value
End Set
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.Mailing1.My.MySettings
Get
Return Global.Mailing1.My.MySettings.Default
End Get
End Property
End Module
End Namespace
В общем пользователь может указать путь к базе данных и имя файла.
Вопрос как это значение подставить в
- Код: Выделить всё
Global.System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""D:\MyProjects\MAIL ID\Mailing1\Mail" & _
"ing.mdb""")>
вместо второй части connection string?
Подсунуть в значение аттрибута переменную не получиться.
Заранее спасибо.
Самые наилучшие пожелания.