locked
Loading user settings for a dynamically loaded assembly RRS feed

  • Question

  • I have an application that dynamically loads an assymbly and creates an instance of a form in the assymbly. Here is a pice of that code:

     

    Dim oAssembly As Reflection.Assembly

    oAssembly = System.Reflection.Assembly.LoadFile(My.Application.Info.DirectoryPath & DLLPath)

     

    Dim oForm As Form = oAssembly.CreateInstance(FormNamespace, True, Reflection.BindingFlags.CreateInstance, Nothing, args, Nothing, Nothing)

     

    oForm.StartPosition = FormStartPosition.CenterParent

    oForm.MdiParent = Me

    oForm.Show()

     

    The assymbly I am loading here has user settings associated with it that are loaded onto the form when the form loads and saved from the form when the form closes. The saving/loading is not happening when I load the form in this way. Does anyone know how to make something like this work?

     

    Thanks,

    Joe

     

    Thursday, May 3, 2007 10:39 PM

Answers

  • Hi sullivan..

    well i dnt thnk so my this post is very helpful 2u.. bt i thnk i can convey the basic idea of users settings..

    also 1 more thing i am not good in vb.. so m posting u a sampe code of C#.. if u can get a basic idea from dat and then code it in VB ..

    firt u need 2 upload application setings using user setting.. and if user made some changes to it.. u need to save these setting.. plz look at da code below am sure it will help ya out ... if u  dnt knw C# den yet u can grab da basic idea..

     

    BestRegards

    SharpLogic

     

    public partial class FormSettings : Form

    {

    #region Feilds

    private string previousSharedFolderPath;

    #endregion

     

    #region Constructor

    public FormSettings()

    {

    InitializeComponent();

    this.LoadApplicationSettings();

    }

    #endregion

     

    #region Functions

    private void LoadApplicationSettings()

    {

    this.chkOnline.Checked = Properties.Settings.Default.PlayOnline;

    this.chkOffline.Checked = Properties.Settings.Default.PlayOffline;

    this.chkRcvdMsg.Checked = Properties.Settings.Default.PayMsgSoundifNotFocus;

    this.chkShowNotification.Checked = Properties.Settings.Default.ShowOnlineNotification;

    this.chkOnTop.Checked = Properties.Settings.Default.KeepOnTop;

    this.txtSharedDir.Text = Properties.Settings.Default.SharedFolderPath;

    this.txtDownloadDir.Text = Properties.Settings.Default.DownloadFolderPath;

    this.txtChatSaveDir.Text = Properties.Settings.Default.SaveChatPath;

    this.chkSaveChat.Checked = Properties.Settings.Default.SaveChat;

    this.txtChatSaveDir.Text = Properties.Settings.Default.SaveChatPath;

    if (Properties.Settings.Default.SaveChat)

    {

    this.txtChatSaveDir.Enabled = true;

    this.btnSaveChatDir.Enabled = true;

    }

    }

    private void SaveSettings()

    {

    Properties.Settings.Default.PlayOnline = this.chkOnline.Checked;

    Properties.Settings.Default.PlayOffline = this.chkOffline.Checked;

    Properties.Settings.Default.PayMsgSoundifNotFocus = this.chkRcvdMsg.Checked;

    Properties.Settings.Default.ShowOnlineNotification = this.chkShowNotification.Checked;

    Properties.Settings.Default.KeepOnTop = this.chkOnTop.Checked;

    Properties.Settings.Default.DownloadFolderPath = this.txtDownloadDir.Text;

    Properties.Settings.Default.SaveChat = this.chkSaveChat.Checked;

    Properties.Settings.Default.SaveChatPath = this.txtChatSaveDir.Text;

    if (this.txtSharedDir.Text != this.previousSharedFolderPath)

    Properties.Settings.Default.SharedFolderChanged = true;

    Properties.Settings.Default.Save();

    }

     

    #region Form's Events

    private void btnBrowse_Click(object sender, EventArgs e)

    {

    FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();

    if (folderBrowserDlg.ShowDialog() == DialogResult.OK)

    this.txtSharedDir.Text = folderBrowserDlg.SelectedPath;

    }

    private void btnBrwoseDownload_Click(object sender, EventArgs e)

    {

    FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();

    if (folderBrowserDlg.ShowDialog() == DialogResult.OK)

    this.txtDownloadDir.Text = folderBrowserDlg.SelectedPath;

    }

    private void btnOK_Click(object sender, EventArgs e)

    {

    this.SaveSettings();

    MessageBox.Show(this, "Some of the settings will not take effect until the appilication is restarted", "Settings",MessageBoxButtons.OK, MessageBoxIcon.Information);

    this.DialogResult = DialogResult.OK;

    }

    private void btnCancel_Click(object sender, EventArgs e)

    {

    this.Close();

    }

    #endregion

    Friday, May 4, 2007 1:38 PM

All replies

  • Hi sullivan..

    well i dnt thnk so my this post is very helpful 2u.. bt i thnk i can convey the basic idea of users settings..

    also 1 more thing i am not good in vb.. so m posting u a sampe code of C#.. if u can get a basic idea from dat and then code it in VB ..

    firt u need 2 upload application setings using user setting.. and if user made some changes to it.. u need to save these setting.. plz look at da code below am sure it will help ya out ... if u  dnt knw C# den yet u can grab da basic idea..

     

    BestRegards

    SharpLogic

     

    public partial class FormSettings : Form

    {

    #region Feilds

    private string previousSharedFolderPath;

    #endregion

     

    #region Constructor

    public FormSettings()

    {

    InitializeComponent();

    this.LoadApplicationSettings();

    }

    #endregion

     

    #region Functions

    private void LoadApplicationSettings()

    {

    this.chkOnline.Checked = Properties.Settings.Default.PlayOnline;

    this.chkOffline.Checked = Properties.Settings.Default.PlayOffline;

    this.chkRcvdMsg.Checked = Properties.Settings.Default.PayMsgSoundifNotFocus;

    this.chkShowNotification.Checked = Properties.Settings.Default.ShowOnlineNotification;

    this.chkOnTop.Checked = Properties.Settings.Default.KeepOnTop;

    this.txtSharedDir.Text = Properties.Settings.Default.SharedFolderPath;

    this.txtDownloadDir.Text = Properties.Settings.Default.DownloadFolderPath;

    this.txtChatSaveDir.Text = Properties.Settings.Default.SaveChatPath;

    this.chkSaveChat.Checked = Properties.Settings.Default.SaveChat;

    this.txtChatSaveDir.Text = Properties.Settings.Default.SaveChatPath;

    if (Properties.Settings.Default.SaveChat)

    {

    this.txtChatSaveDir.Enabled = true;

    this.btnSaveChatDir.Enabled = true;

    }

    }

    private void SaveSettings()

    {

    Properties.Settings.Default.PlayOnline = this.chkOnline.Checked;

    Properties.Settings.Default.PlayOffline = this.chkOffline.Checked;

    Properties.Settings.Default.PayMsgSoundifNotFocus = this.chkRcvdMsg.Checked;

    Properties.Settings.Default.ShowOnlineNotification = this.chkShowNotification.Checked;

    Properties.Settings.Default.KeepOnTop = this.chkOnTop.Checked;

    Properties.Settings.Default.DownloadFolderPath = this.txtDownloadDir.Text;

    Properties.Settings.Default.SaveChat = this.chkSaveChat.Checked;

    Properties.Settings.Default.SaveChatPath = this.txtChatSaveDir.Text;

    if (this.txtSharedDir.Text != this.previousSharedFolderPath)

    Properties.Settings.Default.SharedFolderChanged = true;

    Properties.Settings.Default.Save();

    }

     

    #region Form's Events

    private void btnBrowse_Click(object sender, EventArgs e)

    {

    FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();

    if (folderBrowserDlg.ShowDialog() == DialogResult.OK)

    this.txtSharedDir.Text = folderBrowserDlg.SelectedPath;

    }

    private void btnBrwoseDownload_Click(object sender, EventArgs e)

    {

    FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();

    if (folderBrowserDlg.ShowDialog() == DialogResult.OK)

    this.txtDownloadDir.Text = folderBrowserDlg.SelectedPath;

    }

    private void btnOK_Click(object sender, EventArgs e)

    {

    this.SaveSettings();

    MessageBox.Show(this, "Some of the settings will not take effect until the appilication is restarted", "Settings",MessageBoxButtons.OK, MessageBoxIcon.Information);

    this.DialogResult = DialogResult.OK;

    }

    private void btnCancel_Click(object sender, EventArgs e)

    {

    this.Close();

    }

    #endregion

    Friday, May 4, 2007 1:38 PM
  • Hi Joe,
     
    Check this solution to save/load form settings:
     
     
    Jani
     
    Thursday, May 8, 2008 10:00 AM