开发者

Setting the visibility for a ThumbnailToolBarButton

I've got a few ThumbnailToolBarButtons on my window thumbnail. One is a play/pause button. I've actually got two buttons for this ... one for play and one for pause. When I click the button it will hide one and show the other using the ThumbnailToolBarButton's Visible property. However, while the window thumbnail is up if I click the play/pause button the ThumbnailToolBarButtons all get really wide and suddenly I only see two buttons. If I let the window thumbnail disappear and roll over it again all my buttons are back and the correct widths. What is going on here? Thanks.

Update: Ok. Here is some code as an example.

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 EventH开发者_JS百科andler<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;
}


Try uniting the play/pause buttons into one button, and in the click event handler write:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜