i nedd to change the color to white
im now just learning event handlers.

Dani AI

Generated

The thread mixes web tags and WinForms wording. asked about changing a form backcolor on label hover, while ’s reply uses this.BackColor (WinForms). Two practical options follow: a simple HTML/CSS/JS approach for web pages, and a WinForms/C# approach for desktop apps. For pure styling prefer CSS :hover; for changing a different element (form/body) or needing logic use JS mouseenter/mouseleave (see MDN :hover and ). For WinForms see Control.MouseEnter.

Web (HTML/JS): attach mouseenter and mouseleave to the label and set the target element’s style.backgroundColor. mouseenter does not bubble (preferred over mouseover when child elements are present). Example:

const form = document.getElementById('myForm'); // target element (or document.body)
const label = document.getElementById('myLabel');
const original = form.style.backgroundColor || '';

label.addEventListener('mouseenter', () => { form.style.backgroundColor = 'white'; });
label.addEventListener('mouseleave', () => { form.style.backgroundColor = original; });

WinForms (C#): follow ’s direction but store and restore the original color and attach MouseEnter/MouseLeave. Example:

private Color originalBack;

public Form1()
{
  InitializeComponent();
  originalBack = this.BackColor;
  label1.MouseEnter += (s,e) => this.BackColor = Color.White;
  label1.MouseLeave += (s,e) => this.BackColor = originalBack;
}

Troubleshooting: if events do not fire, confirm the label receives pointer events (web: pointer-events and z-index; WinForms: Enabled true and the label has visible bounds). For many labels attach handlers in a loop rather than duplicating code. Use devtools or breakpoints to verify events are firing.

Recommended Answers

All 3 Replies

Also if anyone has a good reference to learning event handler online please tell me.

Add a method to the MouseEnter event to change this.Backcolor to white.

Add a method to the MouseEnter event to change this.Backcolor to white.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.