Jump to content

Trying to hide/Unhide panel

- - - - -

  • Please log in to reply
11 replies to this topic

#1
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
I can't seem to figure out what I'm doing wrong. I want the panel to be hidden when program launch, but when user move the mouse over the panel area, then panel becomes visible. I try different ways but i must be missing something. Here is current code. Also the visible property is set to false.


private void plMain_MouseEnter(object sender, EventArgs e)
{
if (plMain.Visible == false)
plMain.Visible = true;
}

private void plMain_MouseLeave(object sender, EventArgs e)
{
if (plMain.Visible == true)
plMain.Visible = false;
}

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
You can use a mouse enter on a invisible object. One solution is to just change the background color of the panel:
EDIT: Thid works better:
private void panel1_MouseLeave(object sender, EventArgs e)
        {
            panel1.BackColor = Color.Transparent;
        }

        private void panel1_MouseEnter(object sender, EventArgs e)
        {
            panel1.BackColor = Color.WhiteSmoke;
        }

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
The panel will display settings and options. So I need it to be invisible and visible at times. Will also try other options, either mouseMove, or mouseHover, or anything else I can do to get this to work.

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
OK, now i have some better working code.
 public Form1()
        {
            InitializeComponent();
            panelColor = panel1.BackColor;
            
        }
        Color panelColor = new Color();
      
        private void panel1_MouseLeave(object sender, EventArgs e)
        {
            panel1.BackColor = Color.Transparent;
        }

        private void panel1_MouseEnter(object sender, EventArgs e)
        {
            panel1.BackColor = panelColor;
        }
You will still have to turn the labels and buttons on the panel invisible, and visible on the mouseEnter, and mouseLeave events.

Hope this works ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
Ok, from your ideal I came up with this, because I couldn't get rid of the border and text in buttons with your code.
private void plMain_MouseLeave(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Transparent;

            btnExit.Visible = false;

            btnHome.Visible = false;

            btnSettings.Visible = false;

        }


        private void plMain_MouseEnter(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Turquoise;

            btnExit.Visible = true;

            btnHome.Visible = true;

            btnSettings.Visible = true;

        }


        private void btnExit_MouseEnter(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Turquoise;

            btnExit.Visible = true;

            btnHome.Visible = true;

            btnSettings.Visible = true;

        }


        private void btnExit_MouseLeave(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Transparent;

            btnExit.Visible = false;

            btnHome.Visible = false;

            btnSettings.Visible = false;

        }


        private void btnHome_MouseEnter(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Turquoise;

            btnExit.Visible = true;

            btnHome.Visible = true;

            btnSettings.Visible = true;

        }


        private void btnHome_MouseLeave(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Transparent;

            btnExit.Visible = false;

            btnHome.Visible = false;

            btnSettings.Visible = false;

        }


        private void btnSettings_MouseEnter(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Turquoise;

            btnExit.Visible = true;

            btnHome.Visible = true;

            btnSettings.Visible = true;

        }


        private void btnSettings_MouseLeave(object sender, EventArgs e)

        {

            plMain.BackColor = Color.Transparent;

            btnExit.Visible = false;

            btnHome.Visible = false;

            btnSettings.Visible = false;

        }

Problem is; works great with the panel, but when I go over the buttons they keep flicking.

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Hmm, cant you just use this code?
private void plMain_MouseLeave(object sender, EventArgs e)
        {
            plMain.BackColor = Color.Transparent;
            btnExit.Visible = false;
            btnHome.Visible = false;
            btnSettings.Visible = false;
        }

        private void plMain_MouseEnter(object sender, EventArgs e)
        {
            plMain.BackColor = Color.Turquoise;
            btnExit.Visible = true;
            btnHome.Visible = true;
            btnSettings.Visible = true;
        }
It doenst flash, or do you really need to have the buttons appear when you hover?
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
It still flickers for me. So I tried it on another form, with same setup, and the same thing, but also realized that when i use transparent, it cover up things under it, (ie.. my browser and listbox).

Question, how do you make a item that is invisible,visible. I got the mouse leave event to work with visible = false, just can't get it to work the other way.

#8
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
IM not sure you cna do that.

THis code may work:
private void plMain_MouseLeave(object sender, EventArgs e)
        {
          panel1.SendToBack();
        }

        private void plMain_MouseEnter(object sender, EventArgs e)
        {
            panel1.BringToFront();
        }

A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#9
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
Going to try something in a little bit, will post soon if it works.

#10
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
Ok, I finally got it to work, here is the working code.
private void plOsMain_MouseEnter(object sender, EventArgs e)     //****Outside Panel to trigger the event.

        {

            plMain.Visible = true;

            btnExit.Visible = true;

            btnHome.Visible = true;

            BtnSettings.Visible = true;

            timeMP.Enabled = true;

            timeMP.Interval = 1500;

            timeMP.Tick += new System.EventHandler(timeMP_Tick);

        }


        private void timeMP_Tick(object sender, EventArgs e)

        {

            plMain.Visible = false;

            btnExit.Visible = false;

            btnHome.Visible = false;

            BtnSettings.Visible = false;

        }


#11
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Good for you! Sorry I wasnt able to fix your problem.

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#12
jbnonn

jbnonn

    Newbie

  • Members
  • PipPip
  • 15 posts
Thanks your your help, for everything.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users