Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just wondering, is it possible to make the 3 slide panel with one button ?

What I have tried:

below this is my code, where i need to click 1 button to show 1 panel, so.. if i have 3 panel.. then i need 3 button. The thing that i need is, i just want 1 button to create panel slider (3 panel)


private void button_1(object sender, EventArgs e)
{
    var point = new Point(97,76);
    this.panel2.Location = point;

    this.panel2.Location = new Point(
     this.panel2.Location.X,
     this.panel2.Location.Y);


}

private void button_2(object sender, EventArgs e)
{

    var point2 = new Point(97,76);
    this.panel3.Location = point2;

    this.panel3.Location = new Point(
     this.panel3.Location.X,
     this.panel3.Location.Y);

}

private void button_3(object sender, EventArgs e)
{

    //DEfault
    var point2 = new Point(307, 75);
    this.panel2.Location = point2;

    this.panel2.Location = new Point(
     this.panel2.Location.X,
     this.panel2.Location.Y);


    var point = new Point(97,414);
    this.panel3.Location = point;

    this.panel3.Location = new Point(
     this.panel3.Location.X,
     this.panel3.Location.Y);


}
Posted
Updated 10-Aug-17 18:40pm
v3
Comments
Graeme_Grant 10-Aug-17 21:51pm    
Use a state system to manage what happens when the button is pressed.
Graeme_Grant 10-Aug-17 22:17pm    
I don't understand from your code what it is that you are doing.

Please click on the "Improve question" widget and explain what you are attempting to do...
Karthik_Mahalingam 10-Aug-17 23:09pm    
add those codes in a single button click event.

1 solution

There are a lot of ways you could do this. Here's one:

Handle all Panel positioning in the Click EventHandler of one Button:
private void YourForm_Load(object sender, EventArgs e)
    {
        Panels = new List<Panel> {panel1, panel2, panel3};
    }

    private List<Panel> Panels;

    private int currentPanelIndex = 0;
    private Panel currentPanel;

    private void PanelChangeButton_Click(object sender, EventArgs e)
    {
        currentPanelIndex =
            (currentPanelIndex == 2)
                ? 0
                : ++currentPanelIndex;

        currentPanel = Panels[currentPanelIndex];

        currentPanel.BringToFront();

        switch (currentPanel.Name)
        {
            case "panel1":
                // your positioning code goes here
                break;

            case "panel2":
                break;

            case "panel3":
                break;
        }
    }
}
We keep track of the current Panel, and, with each click on the 'PanelChangeButton, we set the index to point to the next Panel in the series. If we are at the last Panel in the series, we reset the index to point to the first Panel.

In the 'switch/case statements you can write your code to do whatever based on the (new) current panel.

fyi: this code is redundant:
var point = new Point(97,76);
this.panel2.Location = point;

this.panel2.Location = new Point(
 this.panel2.Location.X,
 this.panel2.Location.Y);
It can be replaced with this:
this.panel2.Location = new Point(97,76);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900