如何让windows窗体运行时居中,C#代码提示
时间: 2023-12-02 15:07:29 浏览: 32
你可以使用以下代码将窗体居中显示:
```c#
this.StartPosition = FormStartPosition.CenterScreen;
```
将此代码放在窗体的构造函数中或窗体加载事件中即可。
相关问题
c# tooptip窗体居中显示
在C#中,要让ToolTip窗体居中显示,可以使用以下代码:
```csharp
// 获取屏幕的宽度和高度
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
// 计算ToolTip窗体的位置
int x = (screenWidth - toolTipForm.Width) / 2;
int y = (screenHeight - toolTipForm.Height) / 2;
// 设置ToolTip窗体的位置
toolTipForm.StartPosition = FormStartPosition.Manual;
toolTipForm.Location = new Point(x, y);
```
其中,`toolTipForm`是你的ToolTip窗体对象。这段代码会将ToolTip窗体居中显示在屏幕上。
c#窗体默认居中屏幕
在 C# 窗体中,要将窗体居中显示在屏幕上,可以使用以下代码:
```csharp
this.StartPosition = FormStartPosition.CenterScreen;
```
这将使窗体在屏幕中央显示。也可以在窗体的属性中设置 "StartPosition" 属性为 "CenterScreen"。
另外,如果想将窗体在父窗体中居中显示,可以使用以下代码:
```csharp
this.StartPosition = FormStartPosition.CenterParent;
```
这将使窗体在其父窗体中央显示。