积极答复者
请问 visual studio 的这个菜单栏是怎样实现的

问题
答案
-
您好 彭,
我们可以把默认的标题栏隐藏掉,然后自定义一个新的标题栏。最后通过注册新标题栏的MouseDown事件来实现您所列的需求。以下代码供您参考。
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { if (e.ClickCount == 2) { AdjustWindowSize(); } else { //当窗口最大化的时候,先更改窗口的状态,这样就可以拖动了 if (this.WindowState == WindowState.Maximized) { this.Top = 0; this.Left = 0; this.WindowState = WindowState.Normal; this.Height = SystemParameters.MaximizedPrimaryScreenHeight; this.Width = SystemParameters.MaximizedPrimaryScreenWidth; } Application.Current.MainWindow.DragMove(); } } }
private void AdjustWindowSize() { if (this.WindowState == WindowState.Maximized) { this.WindowState = WindowState.Normal; } else { this.WindowState = WindowState.Maximized; } }
Best Regards,
Li WangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 彭123 2016年9月13日 14:19
全部回复
-
您好 彭,
我们可以把默认的标题栏隐藏掉,然后自定义一个新的标题栏。最后通过注册新标题栏的MouseDown事件来实现您所列的需求。以下代码供您参考。
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { if (e.ClickCount == 2) { AdjustWindowSize(); } else { //当窗口最大化的时候,先更改窗口的状态,这样就可以拖动了 if (this.WindowState == WindowState.Maximized) { this.Top = 0; this.Left = 0; this.WindowState = WindowState.Normal; this.Height = SystemParameters.MaximizedPrimaryScreenHeight; this.Width = SystemParameters.MaximizedPrimaryScreenWidth; } Application.Current.MainWindow.DragMove(); } } }
private void AdjustWindowSize() { if (this.WindowState == WindowState.Maximized) { this.WindowState = WindowState.Normal; } else { this.WindowState = WindowState.Maximized; } }
Best Regards,
Li WangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 彭123 2016年9月13日 14:19