Fixed Menu in Csharp

Asked

Viewed 311 times

3

I would like to know how to have a fixed menu in c#, as the user moves the application, just change the context, similar to web pages.

1 answer

4


This I can answered (I’m making a form like this).

  • First of all you add one splitContainer on his form, after which you change his properties (from splitContainer and not of panels), and changes to vertical or horizontal (according to your form)..

If you want to leave fixed, that is, so that the user can not increase or decrease the size of the panels by dragging the separator, you put True on the property IsSplitterFix.

  • Now you add one menuStrip and put inside the panel1 of splitContainer, fit it automatically into the panel.

  • Create menu options and methods for Click of each one (for this double click on the option), inside the method you put:

    private void novoToolStripMenuItem_Click(object sender, EventArgs e)
    {//esse é meu metodo ao clicar no botao novo do menustrip
        NOME-SPLIT-CONTAINER.NOME-DO-PANEL.Controls.Clear(); // limpa o painel2
        FORM.TopLevel = false; // redefine um level do form (slit nao funciona com form de level superior)
        NOME-SPLIT-CONTAINER.NOME-DO-PANEL.Controls.Add(FORM); //add formulario ao painel 2
    //form é a instancia do formulário que tu quer exibir no panel2 do split, sugiro que crie uma instancia publica e estática
        FORM.Show(); // mostra formulario
    }
    

For each context you will create a form, and create an instance of it in your main form (which has splitContainer), I suggest that these instances are static, so as not to get dirty the memory of the PC, creating new instances whenever a form is called.

Tip: Put this on form same background color and no window (changing property FormBorderStyle for none), so you will give an aspect that is the same form.

Extra: Like you said 'web pages' if you want to just create one form with WebBrowser and display it on panel2.

EDIT

In case you had ever seen, the form that you will insert into the panel will always be in the upper left corner of the panel to fix this and leave it in the center, or as you want, create the form, usually after this select all the items you have in it and take the anchor from the same.. For this go on Propriedades, in anchor let none.

Now another important thing, in your case form is larger (in height or width) than the panel where you want to display it, add to the top code the following lines, remembering that the lines will be added before placing the form in the panel (that is, before the Controls.Add):

int altura = this.NOME-SPLIT-CONTAINER.NOME-DO-PANEL.Height;
int largura = this.NOME-SPLIT-CONTAINER.NOME-DO-PANEL.Width;
FORM.Height = altura;
FORM.Width = largura;

So you make your form receive the same height and width as your panel, if your form is too long at the time just delete the lines from the altura, so it will only show a vertical scroll , no horizontal scroll (which for me is a bag).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.