设置ThumbnailToolBarButton的可见性

时间:2011-09-20 22:02:05

标签: c# .net windows winforms thumbnail-toolbar

我的窗口缩略图上有一些ThumbnailToolBarButtons。一个是播放/暂停按钮。我实际上有两个按钮...一个用于播放,一个用于暂停。当我单击按钮时,它将隐藏一个并使用ThumbnailToolBarButton的Visible属性显示另一个。但是,如果单击播放/暂停按钮,窗口缩略图已启动,ThumbnailToolBarButtons全部变宽,突然我只看到两个按钮。如果我让窗口缩略图消失并再次翻转它,我的所有按钮都会返回并且宽度正确。这里发生了什么?感谢。

更新:好的。以下是一些代码示例。

private ThumbnailToolBarButton buttonPrevious;
private ThumbnailToolBarButton buttonNext;
private ThumbnailToolBarButton buttonPlay;
private ThumbnailToolBarButton buttonPause;
private Boolean bPlaying = false;

private void Form1_Load(object sender, EventArgs e)
{
    buttonPrevious = new ThumbnailToolBarButton(Properties.Resources.previous, "Previous");
    buttonPrevious.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonPrevious_Click);
    buttonPrevious.Visible = true;

    buttonNext = new ThumbnailToolBarButton(Properties.Resources.next, "Next");
    buttonNext.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonNext_Click);
    buttonNext.Visible = true;

    buttonPlay = new ThumbnailToolBarButton(Properties.Resources.play, "Pause/Pause");
    buttonPlay.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonPlay_Click);
    buttonPlay.Visible = true;

    buttonPause = new ThumbnailToolBarButton(Properties.Resources.pause, "Play");
    buttonPause.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(buttonPlay_Click);
    buttonPause.Visible = false;

    TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, buttonPrevious, buttonPlay, buttonPause, buttonNext);
}

private void buttonPlay_Click(object sender, ThumbnailButtonClickedEventArgs e)
{
    bPlaying = !bPlaying;

    buttonPlay.Visible = bPlaying ? false : true;
    buttonPause.Visible = bPlaying ? true : false;
}

1 个答案:

答案 0 :(得分:1)

尝试将播放/暂停按钮合并为一个按钮,并在click事件处理程序中写入:

if ( buttonPlayPause.Icon == Properties.Resources.play )
    buttonPlayPause.Icon = Properties.Resources.pause;
else
    buttonPlayPause.Icon = Properties.Resources.play;