[英]How do i change a control location to be in the center of the screen?
我不想更改屏幕分辨率。 将鼠标移到它正在执行的控制区域上时,我在Form1设计器中有一个用户控件:
private void graphChart1_MouseEnter(object sender, EventArgs e)
{
graphChart1.ChangeChartSize(600, 600);
graphChart1.ChangeChartLocation(0, 0);
}
public void ChangeChartSize(int width, int height)
{
this.Size = new Size(width, height);
chart1.Size = new Size(width, height);
chart1.Invalidate();
}
public void ChangeChartLocation(int x, int y)
{
this.Location = new Point(x, y);
}
但是现在位置是0,0我希望即使控件的大小会比窗体大,也不要紧,我希望控件将其位置更改为屏幕的中心或Form的中心(因为表格已经在中间了)。
将图表移到该位置:
x = (formWidth - chartWidth) / 2;
y = (formHeight - chartHeight) / 2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.