技术开发 频道

VS2010与Win7共舞 :任务栏缩略图

    通过缩略图工具栏控制应用程序

    前面两个例子,都只是对缩略图进行处理,让我们可以直观的了解应用程序的状态。更进一步地,在Windows 7的任务栏缩略图中,我们还可以通过缩略图工具栏直接对应用程序进行操作。例如Windows Media Player的任务栏缩略图中的播放按钮等等。
无疑,缩略图工具栏极大地提高了应用程序的操作效率。通过ThumbButtonManager类,我们也可以方便地为我们的应用程序添加缩略图工具栏。在本文的例子中,我们为缩略图添加一个工具栏,这个工具栏只包含一个按钮(Windows 7的缩略图工具栏最多只能包含7个按钮)。当用户点击这个按钮后,就可以得到关于当前加载的图片的相关信息。

    首先,我们在应用程序主界面上添加一个按钮“缩略图按钮”并将其点击响应函数实现如下:

// 定义Form层级的ThumbButtonManager对象
ThumbButtonManager _thumbButtonManager;
private void ThumbToolBarBtn_Click(object sender, EventArgs e)
{
// 切换状态
if (_thumbButtonManager != null)
{
_thumbButtonManager = null;
}
else
{
// 创建ThumbButtonManager对象
_thumbButtonManager = new ThumbButtonManager(Handle);
//创建工具栏按钮
// 这里我们使用系统图标作为按钮的图标
ThumbButton button =
_thumbButtonManager.CreateThumbButton(101,
SystemIcons.Information, "Open Picures");

// 处理按钮点击消息
button.Clicked += delegate
{
// 获取当前加载的图片的信息
string strInfo = string.Format(" FileLocation: {0} \n Height: {1} \n Width:{2}",
pictureShowBox.ImageLocation,
pictureShowBox.Image.Height,
pictureShowBox.Image.Width);
// 通过消息框显示图片信息
MessageBox.Show(strInfo, "Picture Information");
};

// 将按钮添加到缩略图工具栏中
_thumbButtonManager.AddThumbButtons(button);
}
}
 

0
相关文章