.NET/C#: How to remove/minimize code clutter while 'triggering' Events
- by eibhrum
Hi,
I just wanna find out if there's a way I could minimize code clutter in my application.
I have written code/s similar to this:
private void btnNext_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnNext.Opacity = 1;
}
private void btnNext_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnNext.Opacity = 0.5;
}
private void btnShowAll_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnShowAll.Opacity = 1;
}
private void btnShowAll_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnShowAll.Opacity = 0.5;
}
private void btnPrev_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnPrev.Opacity = 1;
}
private void btnPrev_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnPrev.Opacity = 0.5;
}
private void btnSearch_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnSearch.Opacity = 1;
}
private void btnSearch_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnSearch.Opacity = 0.5;
}
private void btnSearchStore_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnSearchStore.Opacity = 1;
}
private void btnSearchStore_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnSearchStore.Opacity = 0.5;
}
private void btnCloseSearch_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnCloseSearch.Opacity = 1;
}
private void btnCloseSearch_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnCloseSearch.Opacity = 0.5;
}
private void btnHome_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
btnHome.Opacity = 1;
}
private void btnHome_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
btnHome.Opacity = 0.5;
}
and so on and so forth...
Do I need to create a 'function' that will run initially? Or do I have to create another class just so I can 'organize' them?
Any suggestions?