CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Need a little help with some C# code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Mouse_Shaker
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void panel1_MouseEnter(object sender, EventArgs e)
    {
    //Changes Background color of main panel to blue.
    panel3.BackColor = Color.Blue;
    }
    private void panel2_MouseEnter(object sender, EventArgs e)
    {
    //Changes Background color of main panel to red.
    panel3.BackColor = Color.Red;
    }
    private void panel1_Paint(object sender, EventArgs e) {

    }

    }

    }

    so if you couldn't tell from the code, I am trying to get it so that when the mouse enters panel1, panel3 (the main panel) turns blue, and when I enter panel2, panel 3 turns red.

    The only problem is that when I run the program, when the mouse enters panel 1 the background turns blue, but when it enters panel 2, nothing happens, and it doesn't matter if it enters panel 2 first or second, it just won't happen. How do I fix this?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need a little help with some C# code.

    How are the panels arranged on screen? Are they inside one another?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Need a little help with some C# code.

    See attached - is that what you were trying to do?
    Attached Files Attached Files
    It's not a bug, it's a feature!

  4. #4
    Join Date
    Sep 2011
    Posts
    6

    Re: Need a little help with some C# code.

    Quote Originally Posted by worsewicked View Post
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Mouse_Shaker
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void panel1_MouseEnter(object sender, EventArgs e)
    {
    //Changes Background color of main panel to blue.
    panel3.BackColor = Color.Blue;
    }
    private void panel2_MouseEnter(object sender, EventArgs e)
    {
    //Changes Background color of main panel to red.
    panel3.BackColor = Color.Red;
    }
    private void panel1_Paint(object sender, EventArgs e) {

    }

    }

    }

    so if you couldn't tell from the code, I am trying to get it so that when the mouse enters panel1, panel3 (the main panel) turns blue, and when I enter panel2, panel 3 turns red.

    The only problem is that when I run the program, when the mouse enters panel 1 the background turns blue, but when it enters panel 2, nothing happens, and it doesn't matter if it enters panel 2 first or second, it just won't happen. How do I fix this?
    You have not written the code for Mouse exit( Leave). Just write the event for mouse Leave and restore the Panel Color to original Color. Same for the Second Panel. It should solve your problem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured