Reputation: 425
I've got this button, created in code, which had a background image and is transparent. So far so good, it works, the horrible grey background color is gone. EXCEPT for when I hover my mouse over it, the irritating keeps coming back.
So I've tried what I could think of, and that's adding an eventlistener which would change the backgroun color to transparent on MouseHover, Enter and Leave. But nothing seems to work.
Any ideas?
Here's my code so far:
private void CreateFirstScreen() {
mainForm.BackgroundImage = Image.FromFile(@"[img dir]");
Button nextBtn = new Button();
nextBtn.BackColor = Color.Transparent; <== this works!
nextBtn.BackgroundImage = Image.FromFile(@"[img dir]");
nextBtn.FlatStyle = FlatStyle.Flat;
nextBtn.FlatAppearance.BorderSize = 0;
nextBtn.SetBounds(1555, 820, 274, 106);
mainForm.Controls.Add(nextBtn);
nextBtn.MouseHover += (sender, args) => {
nextBtn.BackColor = Color.Transparent; <= doesn't work
};
nextBtn.MouseEnter += (sender, args) => {
nextBtn.BackColor = Color.Transparent; <= doesn't work
};
nextBtn.MouseLeave += (sender, args) => {
nextBtn.BackColor = Color.Transparent; <= doesn't work
};
nextBtn.Click += (sender, args) => {
CreateSecondScreen(); <= does work
mainForm.Controls.Remove(nextBtn); <= does work
};
}
Upvotes: 2
Views: 4182
Reputation: 322
Try adding this:
nextBtn.FlatAppearance.MouseOverBackColor=Color.Transparent;
Upvotes: 4