如何在第二台显示器(屏幕)上隐藏 window 的一部分
How to hide part of the window on the second monitor(screen)
window 转到第二台显示器,但应该不可见。如何隐藏区域?
不清楚您为什么需要这个,但可以通过一些努力来实现。诀窍是 OpacityMask 属性,它允许使元素部分透明。一些给你粗略想法的代码:
public MainWindow() {
InitializeComponent();
this.WindowStyle = WindowStyle.None; // required for AllowsTransparency
this.AllowsTransparency = true; // allow window to be transparent
var group = new DrawingGroup();
// make first 100x1000 part of window transparent
group.Children.Add(new GeometryDrawing() {Brush = Brushes.Transparent, Geometry = new RectangleGeometry(new Rect(0, 0, 100, 1000))});
// make the rest part white or whatever color you use
group.Children.Add(new GeometryDrawing() {Brush = Brushes.White, Geometry = new RectangleGeometry(new Rect(100, 0, 1000, 1000))});
this.OpacityMask = new DrawingBrush(group) {
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
AlignmentY = AlignmentY.Top
};
}
window 转到第二台显示器,但应该不可见。如何隐藏区域?
不清楚您为什么需要这个,但可以通过一些努力来实现。诀窍是 OpacityMask 属性,它允许使元素部分透明。一些给你粗略想法的代码:
public MainWindow() {
InitializeComponent();
this.WindowStyle = WindowStyle.None; // required for AllowsTransparency
this.AllowsTransparency = true; // allow window to be transparent
var group = new DrawingGroup();
// make first 100x1000 part of window transparent
group.Children.Add(new GeometryDrawing() {Brush = Brushes.Transparent, Geometry = new RectangleGeometry(new Rect(0, 0, 100, 1000))});
// make the rest part white or whatever color you use
group.Children.Add(new GeometryDrawing() {Brush = Brushes.White, Geometry = new RectangleGeometry(new Rect(100, 0, 1000, 1000))});
this.OpacityMask = new DrawingBrush(group) {
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
AlignmentY = AlignmentY.Top
};
}