【WPF】label滑鼠懸停提示、背景色
阿新 • • 發佈:2019-01-13
效果
功能
1.滑鼠懸停顯示提示資訊
2.滑鼠劃過修改背景色
3.滑鼠離開恢復背景色
程式碼
設計介面
ToolTip屬性用於設定滑鼠懸停顯示提示資訊
<Label Name="lblClose" Content=" X" ToolTip="關閉" Foreground="White" MouseLeftButtonDown="lblClose_MouseLeftButtonDown"
MouseEnter="lblClose_MouseEnter" MouseLeave="lblClose_MouseLeave" />
後臺
/// <summary> /// 關閉-滑鼠劃過事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lblClose_MouseEnter(object sender, MouseEventArgs e) { lblClose.Background = System.Windows.Media.Brushes.SlateGray; } /// <summary> /// 關閉-滑鼠離開事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lblClose_MouseLeave(object sender, MouseEventArgs e) { lblClose.Background = System.Windows.Media.Brushes.Transparent; }