我正在创建用于屏幕选择的WPF应用程序。我正在尝试在屏幕上绘制一个红色的矩形框。在主显示器上绘画时,我看不到任何问题,选择范围内。我看到辅助显示器出现问题,左侧和顶部都看不到。
这是我的代码:
monitor_index is nothing but the index of the screen selection.
{ System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[Convert.ToInt32(monitor_index)];
var StartPoint = new System.Drawing.Point(0, 0);
var EndPoint = new System.Drawing.Point(screen.Bounds.Width, screen.Bounds.Height);
selectedAreaControl = new Form
{
TopMost = true,
ShowInTaskbar = false,
BackColor = Color.LightGreen,
TransparencyKey = Color.LightGreen,
FormBorderStyle = FormBorderStyle.None,
Name="redborder"
};
selectedAreaControl.Paint += new PaintEventHandler(OnSelectedAreaPaint);
selectedAreaControl.StartPosition = FormStartPosition.Manual;
selectedAreaControl.Location = screen.Bounds.Location;
selectedAreaControl.Bounds = new Rectangle(selectedAreaControl.Location, new Size((EndPoint.X - StartPoint.X), (EndPoint.Y - StartPoint.Y)));
selectedAreaControl.Left = selectedAreaControl.Location.X + StartPoint.X;
selectedAreaControl.Top = selectedAreaControl.Location.Y + StartPoint.Y;
selectedAreaControl.Show();
}
private void OnSelectedAreaPaint(object sender, PaintEventArgs e)
{
Rectangle rect = selectedAreaControl.ClientRectangle;
Pen pen = new Pen(new SolidBrush(borderColor), borderWidth);
e.Graphics.DrawRectangle(pen, rect);
}