我想在C#Windows窗体中制作一个Windows覆盖图,但它不会填充我的设置上的第二个屏幕。我使用的命令找出所有的屏幕分辨率:C#窗体不会填满整个屏幕
表1:
Rectangle a;
Rectangle b;
public Form1()
{
InitializeComponent();
pictureBox1.Hide();
pictureBox2.Hide();
Positions();
int i = 0;
foreach (Screen S in AllScreens)
{
if (i == 0)
{
a = S.Bounds;
i++;
}
else
{
b = S.Bounds;
}
}
FormBorderStyle = FormBorderStyle.None;
Work();
IDK(b);
}
void Work()
{
Height = a.Height;
Width = a.Width;
}
void MsgBox(string a)
{
MessageBox.Show(a);
}
void IDK(Rectangle b)
{
int showOnMonitor = 1;
Screen[] sc;
sc = AllScreens;
Form2 f = new Form2(b)
{
FormBorderStyle = FormBorderStyle.None,
Left = sc[showOnMonitor].Bounds.Left,
Top = sc[showOnMonitor].Bounds.Top,
StartPosition = FormStartPosition.Manual
};
f.Show();
}
void Positions()
{
label1.Location = new Point(
Width/2 - label1.Width/2,
Height/2 - label1.Height - 40);
label1.Anchor = AnchorStyles.None;
button1.Location = new Point(
Width/2 - button1.Width/2,
Height/2 - button1.Height + 40);
button1.Anchor = AnchorStyles.None;
linkLabel1.Location = new Point(
Width/2 - linkLabel1.Width/2,
Height/2 - linkLabel1.Height + 500);
linkLabel1.Anchor = AnchorStyles.None;
}
private void button1_Click(object sender, EventArgs e)
{
LoadGUI();
MsgBox(Width.ToString());
MsgBox(Height.ToString());
}
void LoadGUI()
{
label1.Hide();
button1.Hide();
linkLabel1.Hide();
pictureBox1.Show();
pictureBox1.Location = new Point(20, 20);
pictureBox1.Anchor = AnchorStyles.None;
pictureBox2.Show();
pictureBox2.Location = new Point(20, 188);
pictureBox2.Anchor = AnchorStyles.None;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Application.Exit();
}
表2:
Rectangle a;
public Form2(Rectangle b)
{
InitializeComponent();
a = b;
Work();
}
void Work()
{
Height = a.Height;
Width = a.Width;
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
的问题是,表2不会充满整个第2屏幕。 我不知道为什么屏幕没有完全填满,代码工作了一天前,但它后Windows更新(我不知道这是否是问题。)。对于我所知道的这将永远不会工作...任何帮助将不胜感激。 -Alex
图片证明: Image (右下)
什么码的地方我用这种替换形式1 ? – user6481546
和我的视觉工作室说SetScreen不存在 – user6481546
我编辑了我的答案,以便您可以用我的替换您的Form1初始化代码。关注SetScreen,我创建了一个单独的静态类“setScreen”。编辑这一点 - 只要确保它在相同的名称空间。 – ainwood