Windows Vista的侧边栏等效侧边、Windows、Vista

2023-09-03 07:07:50 作者:盗墓挖坟接单ゝ

我想创建一个类似于Windows Vista边栏的应用程序。这里有一个API,允许停靠的工具栏在屏幕上(AppBar),但它不是我在寻找什么。

I'm trying to create an application that looks similar to the Windows Vista sidebar. There's an API that allows docking toolbars on the screen (AppBar), but it's not exactly what I'm looking for.

我如何可以附加一个表单到桌面,并停靠在屏幕的一侧,但没有重叠它preventing其他窗口?

How can I attach a Form to the desktop and dock it to the side of the screen, but without preventing other windows from overlapping it?

推荐答案

通过下面的所有选项,你会得到一个侧边栏的外观像我(的code以下是一个WPF窗口):

With all the following options you get a Sidebar look-a-like (the code below is for a WPF Window):

//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;

希望这有助于!

Hope this helps!

更新:

下面是你使用WindowsForms时,altough与WPF你​​有更多的可能性,类似的解决方案!差异是次要的,一切都解释本身。我加了最后一行隐藏窗口的任务栏图标。不要将code的形态的构造,但在负载情况下,否则位置将是错误的。在WPF这并不重要。

Here's a similar solution for when you're using WindowsForms, altough with WPF you have much more possibilities! The differences are minor, everything explains itself. The last line I added hides the window taskbar-icon. Do not place the code in the constructor of the Form but in the Load-event, otherwise the Location will be wrong. In WPF this doesn't matter.

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;