Fixed Menu in Csharp

3

I would like to know how to do a fixed menu in C #, as the user moves the application, just change the context, similar to Web pages.

    
asked by anonymous 03.07.2015 / 04:58

1 answer

4

This I can answer (I'm making a form like this).

  • First of all, you add a splitContainer to your form, after that you change its properties (from splitContainer to panels ), and change 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 tab, you put True in the IsSplitterFix property.

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

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

    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 on your main form (which has splitContainer ), I suggest that these instances be static, so as not to get PC memory dirty, creating new instances whenever a form is called.

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

Extra: As you said web pages if you want, just create a form with WebBrowser and display it in panel2 .

EDIT

In case you have already seen, the form that you will insert in the panel will always be in the upper left corner of panel to correct this and leave it in the center, or whatever you like, create the form , usually after that select all the items that you have in it and take the anchor of them. To do this go in Propriedades , in anchor let none .

Now another important thing, if your form is higher (in height or width) than the panel you want to display it in, add the following lines to the code above, remembering that the lines will be added before putting form into panel (ie before 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 get your form to receive the same height and width of your panel , if your form is too long at the time, just delete the lines from altura , so it will only show a vertical scroll, no horizontal scroll (which for me is a sack).

    
03.07.2015 / 06:10