• Using a layout file to preserve user changes in the CommandManager [Janus UI and Ribbon Controls v3.5 for .NET]

    Use a layout file to preserve UICommandManager component settings. Using a layout file you could be able to preserve even the changes to the layout made by the user.

    In VB:



    Private Sub LoadLayout()

    Dim LayoutDir As String = "C:\UIBarsLayout.xml"

    Dim LayoutStream As FileStream

    LayoutStream = New FileStream(LayoutDir, FileMode.Open)

    CommandManager1.LoadLayoutFile(LayoutStream)

    LayoutStream.Close()

    End Sub

    Private Sub CommandManager1_CurrentLayoutChanging(ByVal sender As Object, _

    ByVal e As System.ComponentModel.CancelEventArgs) Handles _

    CommandManager1.CurrentLayoutChanging



    'tTo persist user changes in the current layout,

    'call the Update method explicitly before changing the layout

    If Not CommandManager1.CurrentLayout Is Nothing Then

    CommandManager1.CurrentLayout.Update()

    End If

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

    Dim Result As DialogResult

    Dim LayoutDir As String

    Dim LayoutStream As FileStream





    Result = MessageBox.Show("Do you want to preserve the changes in the" & _

    "CommandManager layout?", "Preserve changes", _

    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

    If Result = Windows.Forms.DialogResult.Cancel Then

    e.Cancel = True

    ElseIf Result = Windows.Forms.DialogResult.Yes Then

    LayoutDir = "C:\UIBarsLayout.xml"

    LayoutStream = New FileStream(LayoutDir, FileMode.Create)

    CommandManager1.SaveLayoutFile(LayoutStream)

    LayoutStream.Close()

    End If



    End Sub


    In C#:



    private void LoadLayout()

    {

    string layoutDir = @"C:\UIBarsLayout.xml";

    FileStream layoutStream;

    layoutStream = new FileStream(layoutDir, FileMode.Open);

    CommandManager1.LoadLayoutFile(layoutStream);

    layoutStream.Close();

    }

    private void commandManager1_CurrentLayoutChanging(object sender,

    System.ComponentModel.CancelEventArgs e)

    {

    //To persist user changes in the current layout,

    //call the Update method explicitly before changing the layout

    if (commandManager1.CurrentLayout != null)

    {

    commandManager1.CurrentLayout.Update();

    }

    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)

    {

    DialogResult result;

    string layoutDir;

    FileStream layoutStream;



    result = MessageBox.Show("Do you want to preserve the changes in the CommandManager layout?",

    "Preserve changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);



    if (result == DialogResult.Cancel)

    {

    e.Cancel = true;

    }

    else if (result == DialogResult.Yes)

    {

    layoutDir = @"C:\UIBarsLayout.xml";

    layoutStream = new FileStream(layoutDir, FileMode.Create);

    commandManager1.SaveLayoutFile(layoutStream);

    layoutStream.Close();

    }

    }

    Source Of Information : Janus v3.5 Help Files for VS 2008


0 comments:

Leave a Reply