如何使用mouseClick事件重写mouseLeave事件
我想知道是否有人可以帮我在按钮效果上我正在为Windows C#论坛工作。如何使用mouseClick事件重写mouseLeave事件
所以我有两个相似的图像,一个背景发光,另一个没有,创建一个按钮。 我使用mouseEnter(glow)
和mouseLeave(normal)
给一个效果很好的按钮。
我有8个不同的按钮在同一个窗体上,为此有不同的图像。
我希望mouseEnter事件继续后,我鼠标点击即发光效果的按钮,但我无法得到一个正确的解决方案。 当点击不同的(下一个)按钮时,发光的按钮应该恢复正常。
想知道是否有人能够指引我走向正确的方向,做了一些网上搜索还没有能够拿出解决方案。
private void btnSong1_MouseEnter(object sender, EventArgs e)
{
this.btnSong1.BackgroundImage =
((System.Drawing.Image)(Properties.Resources.satisfactionH));
}
private void btnSong1_MouseLeave(object sender, EventArgs e)
{
this.btnSong1.BackgroundImage =
((System.Drawing.Image)(Properties.Resources.satisfaction));
}
private void btnSong1_Click(object sender, EventArgs e)
{
nowPlaying1.Visible = Enabled;
nowPlaying2.Visible = false;
nowPlaying5.Visible = false;
this.btnSong1.BackgroundImage =
((System.Drawing.Image)(Properties.Resources.satisfactionH));
axWindowsMediaPlayer1.URL =
@"C:\MediaFile\music\ArethaFranklin\(I Can't Get No) Satisfaction.mp3";
}
private void btnSong2_Click(object sender, EventArgs e)
{
this.btnSong1.BackgroundImage =
((System.Drawing.Image)(Properties.Resources.satisfaction));
axWindowsMediaPlayer1.URL = @"C:\MediaFile\music\ArethaFranklin\Come To Me.mp3";
nowPlaying1.Visible = false;
nowPlaying2.Visible = Enabled;
nowPlaying5.Visible = false;
}
你试过用你自己的buttonClass。我做了一个快速演示GlowingButton
。在点击时播放给定的歌曲,在鼠标进入时发光,并在请假或点击时重置背景。
// don't forget: using System.Runtime.InteropServices;
class GlowingButton : System.Windows.Forms.Button
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,
StringBuilder strReturn,
int iReturnLength,
IntPtr hwndCallback);
public string SongURL { get; set; }
public GlowingButton() : base()
{
this.BackgroundImage = Winforms_Demo.Properties.Resources.bg;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.BackgroundImage = Winforms_Demo.Properties.Resources.bgGlow;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.BackgroundImage = Winforms_Demo.Properties.Resources.bg;
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
this.BackgroundImage = Winforms_Demo.Properties.Resources.bg;
if (!string.IsNullOrEmpty(SongURL))
{
mciSendString("open \"" + SongURL + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);
mciSendString("play MediaFile", null, 0, IntPtr.Zero);
}
}
}
在你的表格你需要做的就是设定一个songUrl为每个glowingButton(通过设计师或源内)!
谢谢Pilgerstorfer Franz,它只有一个按钮,但我的表单上有8个不同的按钮。每个按钮都与不同的歌曲有关。当我点击下一个按钮时,我希望第一个按钮(或哪个按钮)发光效果恢复正常。 – 2012-08-18 02:28:34
重写了我给出的答案 - 请看一看 – 2012-08-18 12:11:01
到目前为止,你有什么代码可以显示你有什么,以便我们可以根据现有的代码获得更直观的想法..? – MethodMan 2012-08-17 13:58:13
'我正在为Windows C#论坛'工作。你的意思是“windows窗体”吗? – 2012-08-17 13:59:28
Yeha告诉我们你正在开发什么平台(Windows窗体或网页),我怀疑你是因为你提到论坛而在网上。 – 2012-08-17 14:05:26