• Using a layout file to preserve user changes [Janus ButtonBar Control v3.5 for .NET]

    How to save and load a layout file to preserve ButtonBar control settings. Using a layout file you could be able to preserve even the changes to the layout made by the user.


    The steps followed to create this project are:


    1) Create a new Visual Basic or C# project using "Windows Application" Template.


    2) Add a ButtonBar control to Form1.


    3) Add a button and change its Text property to "Load".


    4) In the Click event of the load button, load the layout from a file calling a procedure similar to
    the following:


    In VB:


    Private Sub LoadLayout()
    Dim LayoutDir As String = GetLayoutDirectory() + "\ButtonBarLayout.bbl"
    Dim LayoutStream As FileStream
    LayoutStream = New FileStream(LayoutDir, FileMode.Open)
    ButtonBar1.LoadLayoutFile(LayoutStream)
    LayoutStream.Close()
    End Sub


    In C#:


    private void LoadLayout()
    {
    string layoutDir = GetLayoutDirectory() + @"\ButtonBarLayout.bbl";
    FileStream layoutStream;
    layoutStream = new FileStream(layoutDir, FileMode.Open);
    buttonBar1.LoadLayoutFile(layoutStream);
    layoutStream.Close();
    }


    5) Add a button and change its Text property to "Save"


    6) In the Click event of the save button, save the layout from to file calling a procedure similar to
    the following:


    In VB:


    Private Sub SaveLayout()
    Dim LayoutDir As String = GetLayoutDirectory() + "\ButtonBarLayout.bbl"
    Dim LayoutStream As FileStream
    LayoutStream = New FileStream(LayoutDir, FileMode.Create)
    ButtonBar1.SaveLayoutFile(LayoutStream)
    LayoutStream.Close()
    End Sub


    In C#:


    private void SaveLayout()
    {
    string layoutDir = GetLayoutDirectory() + @"\ButtonBarLayout.bbl";
    FileStream layoutStream;
    layoutStream = new FileStream(layoutDir, FileMode.Create);
    buttonBar1.SaveLayoutFile(layoutStream);
    layoutStream.Close();
    }



    You can also save a layout by calling the Update method of the Layout.


    In VB:


    If Not ButtonBar1.CurrentLayout Is Nothing Then
    ButtonBar1.CurrentLayout.Update()
    End If


    In C#:


    if(buttonBar1.CurrentLayout!=null)
    {
    buttonBar1.CurrentLayout.Update();
    }



    7) Run the project.

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


0 comments:

Leave a Reply