2012-03-08 59 views
1

我正在嘗試創建類似於Windows Vista邊欄的應用程序。有一個API允許在屏幕上對接工具欄(AppBar),但它不完全是我要找的。Windows Vista邊欄等效

如何將窗體附加到桌面並將其停靠在屏幕的一側,但不阻止其他窗口重疊?

+0

這需要不斷檢查以確保窗口在前臺。 – 2012-03-08 12:48:36

+1

只需更改窗口的屬性即可。 TopMost,CanResize,並將其設置爲無窗口。然後,您可以將窗口的位置更改爲屏幕的最右側和屏幕的高度,並考慮任務欄並設置好。 – 2012-03-08 12:49:01

+0

不應該有任何解決方案使用AppBar進行對接,但沒有重疊預防? – SharpAffair 2012-03-08 12:57:07

回答

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,altough與WPF,你有更多的可能性,類似的解決方案!差異很小,一切都解釋清楚。我添加的最後一行隱藏了窗口任務欄圖標。不要將代碼放置在Form的構造函數中,而是放在Load事件中,否則位置將會出錯。在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; 
+0

Windows窗體沒有Background屬性。這聽起來像WPF。此外,代碼似乎不一致。 – SharpAffair 2012-03-08 13:17:52

+1

我可以問,什麼阻止你使用WPF比WinForms? – 2012-03-08 13:30:12

+0

查看我的WinForms解決方案的更新答案。 @SandeepBansal:我在想同樣的事情! :d – Abbas 2012-03-08 13:59:53