[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

2 sliding panels

Posted on 2015-01-20
2
Medium Priority
?
162 Views
Last Modified: 2015-01-20
I have 2 sliding panels. When I click 1 button its panel slides in - disables the other button from allowing the second panel to slide. And if you click the same button again it slides the panel back off screen and re enables the second panel button.
What I would like to do is when I click on a button if the other panel is visible then hide it the show its own panel
        private void btnSent_Click(object sender, EventArgs e)
        {
            if (btnInTransit.Enabled == true)
            {
                btnInTransit.Enabled = false;
            }
            else
            {
                btnInTransit.Enabled = true;
            }
            btnSent.Enabled = false;
            if (PanelLocation == 1)
            {
                panel2.Visible = true;
                //if showing - hide
                for (int i = 0; i < panel2.Width; i++)
                {
                    panel2.Location = new Point(746 + i, panel2.Location.Y);
                }
                PanelLocation = 0;
                panel2.Visible = false;
            }
            else
            {
                //if hidding - show
                panel2.Visible = true;
                for (int i = 0; i < panel2.Width; i++)
                {
                    panel2.Location = new Point(1017 - i, panel2.Location.Y);
                    panel2.Invalidate();
                }
                PanelLocation = 1;
            }
            btnSent.Enabled = true;
        }
        private void btnInTransit_Click(object sender, EventArgs e)
        {
            if (btnSent.Enabled == true)
            {
                btnSent.Enabled = false;
            }
            else
            {
                btnSent.Enabled = true;
            }
            btnInTransit.Enabled = false;
            if (PanelLocation == 1)
            {
                panel1.Visible = true;
                //if showing - hide
                for (int i = 0; i < panel1.Width; i++)
                {
                    panel1.Location = new Point(746 + i, panel1.Location.Y);
                }
                PanelLocation = 0;
                panel1.Visible = false;
            }
            else
            {
                //if hidding - show
                panel1.Visible = true;
                for (int i = 0; i < panel1.Width; i++)
                {
                    panel1.Location = new Point(1017 - i, panel1.Location.Y);
                    panel1.Invalidate();
                }
                PanelLocation = 1;
            }
            btnInTransit.Enabled = true;
        }

Open in new window

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 40560173
Assuming neither Panel is visible when you start:
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private enum PanelState
        {
            None, 
            Sent, 
            InTransit
        }

        private PanelState CurrentPanel = PanelState.None;

        private void btnSent_Click(object sender, EventArgs e)
        {
            switch(CurrentPanel)
            {
                case PanelState.InTransit:
                    ShowPanel(panel1, false); // InTransit panel is currently showing, hide it..
                    ShowPanel(panel2, true); // ...then show the Sent panel.
                    CurrentPanel = PanelState.Sent;
                    break;
                case PanelState.None:
                    ShowPanel(panel2, true); // Nothing currently displayed, just show the Sent panel
                    CurrentPanel = PanelState.Sent;
                    break;
                case PanelState.Sent:
                    ShowPanel(panel2, false); // Sent panel is currently showing, hide it.
                    CurrentPanel = PanelState.None;
                    break;
            }
        }

        private void btnInTransit_Click(object sender, EventArgs e)
        {
            switch (CurrentPanel)
            {
                case PanelState.Sent:
                    ShowPanel(panel2, false); // Sent panel is currently showing, hide it..
                    ShowPanel(panel1, true); // ...then show the InTransit panel.
                    CurrentPanel = PanelState.InTransit;
                    break;
                case PanelState.None:
                    ShowPanel(panel1, true); // Nothing currently displayed, just show the InTransit panel
                    CurrentPanel = PanelState.InTransit;
                    break;
                case PanelState.InTransit:
                    ShowPanel(panel1, false); // InTransit panel is currently showing, hide it.
                    CurrentPanel = PanelState.None;
                    break;
            }
        }

        private void ShowPanel(Panel pnl, bool Visible)
        {
            if (Visible)
            {
                // slide out to the left
                pnl.Visible = true;
                for (int i = 0; i < pnl.Width; i++)
                {
                    pnl.Location = new Point(1017 - i, pnl.Location.Y);
                    pnl.Invalidate();
                }
            }
            else
            {
                // slide in to the right
                for (int i = 0; i < pnl.Width; i++)
                {
                    pnl.Location = new Point(746 + i, pnl.Location.Y);
                    pnl.Invalidate();
                }
                pnl.Visible = false;
            }
        }

    }

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40560240
Awesome Mike thank you very much!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question