0

Hey so I am attempting to create a form in which there are two buttons (acting as tabs) on the side in which when one is pressed specific controls are shown and when the other is pressed, another set are shown.

I have gotten this to work very well however I have run into an issue when about to create my second set of controls, how am I going to draw them (in designer) ontop of current controls (it's fine during runtime)? So my question is, how can I make this work. Current (possibly) important code:

private void CheatButton_Click(object sender, EventArgs e)
    {
        CheatControls(true);
        ColorControls(false);

        CheatButton.Normalcolor = Color.FromArgb(51, 51, 51);
        ColorButton.Normalcolor = Color.FromArgb(61, 61, 61);
    }

    private void ColorButton_Click(object sender, EventArgs e)
    {
        CheatControls(false);
        ColorControls(true);

        CheatButton.Normalcolor = Color.FromArgb(61, 61, 61);
        ColorButton.Normalcolor = Color.FromArgb(51, 51, 51);
    }

private void CheatControls(bool b)
    {
        TriggerSwitch.Visible = b;
        TriggerLabel.Visible = b;

        BhopSwitch.Visible = b;
        BhopLabel.Visible = b;

        GlowSwitch.Visible = b;
        GlowLabel.Visible = b;

        RecoilSwitch.Visible = b;
        RecoilLabel.Visible = b;
    }

    private void ColorControls(bool c)
    {

    }

My windows form application with an understandable graphic

  • You could use z-index (that determines the order) – EpicKip Sep 21 '17 at 13:11
  • 1
    How about not cheating tab behaviour but using a real tab control instead? You find it in Toolbox => Container – LocEngineer Sep 21 '17 at 13:11
  • Hey @LocEngineer I would do that but how could I go about implementing it into the design I currently have as I really quite like it. – JordanTheNoob Sep 21 '17 at 13:21
  • 1
    Put all your cheat controls in a custom `UserControl` and all your color controls in a different custom `UserControl`. You can edit the different control sets easily in the designer, and in your code you can hide/show them more easily by setting the appropriate `UserControl`'s visibility rather than setting the visibility of a bunch of controls individually. Here's an (admittedly old) example of creating a `UserControl`: https://msdn.microsoft.com/en-us/library/aa302342.aspx – wablab Sep 21 '17 at 13:23
  • Thanks heaps, @wablab I'll give it a go. Is it a separate designer or is there a hide or show option or? – JordanTheNoob Sep 21 '17 at 13:26
  • When you create a `UserControl` in Visual Studio, you can add the controls to it using the designer. In your form with the tab buttons, you would add instances of the two `UserControl`s that you created. Since `UserControl` derives from `Control`, it has a `Visible` property. So, in your `CheatControls(bool b)` method, your implementation would be simplified to something like `_myCheatControls.Visible = b;`. I haven't watched the whole thing, but this video might help, too: https://www.youtube.com/watch?v=l5L_q_jI494 – wablab Sep 21 '17 at 13:29
  • @wablab Thanks very much! – JordanTheNoob Sep 21 '17 at 13:32
  • No problem. I'll put this as an answer. Please mark it as accepted if it helped so that others can find the solution later. – wablab Sep 21 '17 at 13:33

3 Answers3

2

Put all your cheat controls in a custom UserControl and all your color controls in a different custom UserControl. You can edit the different control sets easily in the designer, and in your code you can hide/show them more easily by setting the appropriate UserControl's visibility rather than setting the visibility of a bunch of controls individually. Here's an (admittedly old) example of creating a UserControl: msdn.microsoft.com/en-us/library/aa302342.aspx

When you create a UserControl in Visual Studio, you can add the controls to it using the designer. In your form with the tab buttons, you would add instances of the two UserControls that you created. Since UserControl derives from Control, it has a Visible property. So, in your CheatControls(bool b) method, your implementation would be simplified to something like _myCheatControls.Visible = b;. I haven't watched the whole thing, but this video might help, too: youtube.com/watch?v=l5L_q_jI494

wablab
  • 1,703
  • 13
  • 15
  • One last minor issue! `private void CheatControls(bool b) { PanelsCheats.Visible = b; }` does not seem to hide it! Any help? – JordanTheNoob Sep 21 '17 at 13:56
  • Does this apply to your situation? https://stackoverflow.com/questions/11161160/c-sharp-usercontrol-visible-property-not-changing – wablab Sep 21 '17 at 14:32
0

You can use XanderUI

Simply add a SuperButton(acts as a tab button) and when its clicked show a panel with your controls in it

EG -

    private void ShowControlSet(int ControlSet)
    {
        panel1.visible = false;
        panel2.visible = false;
        if (ControlSet == 1) panel1.visible = true;
        if (ControlSet == 2) panel2.visible = true;
    }

// To show a panel use
ShowControlSet(1);

Your also able to use BringToFront() instead of making each panel invisible / visible but you need to anchor or dock the panels correctly

-1

asides the visibility, what you can do is get the position of the buttons and st them when hiding and showing the other buttons

just set the top and left positions, ensuring the buttons are the same size.

wale A
  • 81
  • 1
  • 7