0

我想知道是否有人可以帮助我解决我正在为 windows c# 论坛工作的按钮效果。

所以我有两个相似的图像,一个有背景发光,另一个没有,来创建一个按钮。我正在使用mouseEnter(glow)andmouseLeave(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;
} 
4

1 回答 1

1

您是否尝试过使用自己的按钮类。我做了一个快速演示GlowingButton。单击时播放给定的 songUrl,鼠标进入时发光并在离开或单击时重置背景。

// 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 通过设计器或在您的源中)!

于 2012-08-17T15:26:42.353 回答