Windows Vista边栏等效

时间:2012-03-08 12:36:10

标签: c# .net winforms sidebar

我正在尝试创建一个类似于Windows Vista侧边栏的应用程序。有一个API允许在屏幕上对接工具栏(AppBar),但它并不是我正在寻找的。

如何将表格附加到桌面并将其停靠在屏幕的一侧,但不阻止其他窗口重叠?

1 个答案:

答案 0 :(得分:1)

使用以下所有选项,您可以获得侧边栏外观(下面的代码适用于WPF窗口):

//width of the sidebar
Width = 300;
//height (remember to add a reference to the System.Windows.Forms dll)
Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
//no window style means no border
WindowStyle = WindowStyle.None;
//not resizable
ResizeMode = ResizeMode.NoResize;
//allow a transparent sidebar
AllowsTransparency = true;
//change the color
Background = new SolidColorBrush(Colors.CadetBlue);
//set the opacity (how much transparent)
Opacity = 0.5d;
//offset from the top
Top = 0;
//offset from the left (calculated so it shows on the right side)
Left = SystemParameters.PrimaryScreenWidth - (double)GetValue(WidthProperty);
//set it the topmost window
Topmost = true;
//hide the icon from the taskbar
ShowInTaskbar = false;

希望这有帮助!

<强>更新

这是一个类似的解决方案,当你使用WindowsForms时,尽管使用WPF,你还有更多的可能性!一切都是微不足道的,一切都在解释。我添加的最后一行隐藏了窗口任务栏图标。不要将代码放在Form的构造函数中,而是放在Load-event中,否则Location会出错。在WPF中,这无关紧要。

Width = 300;
Height = Screen.PrimaryScreen.Bounds.Height;
FormBorderStyle = FormBorderStyle.None;
BackColor = Color.CadetBlue;
Opacity = 0.5d;
Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width, 0);
TopMost = true;
ShowInTaskbar = false;