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?
Re: Need a little help with some C# code.
How are the panels arranged on screen? Are they inside one another?
1 Attachment(s)
Re: Need a little help with some C# code.
See attached - is that what you were trying to do?
Re: Need a little help with some C# code.
Quote:
Originally Posted by
worsewicked
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