c# winform 怎样让窗体启动位置位于屏幕右上角

2024-11-22 01:49:33
推荐回答(4个)
回答1:

如QQ窗口一样的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
int state;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
this.Top = 0;
state = 0;
}

private void Form1_MouseEnter(object sender, EventArgs e)
{
if (state == 0)
{
state = 1;
int t = this.Top;
for (int i = t; i <= 0; i++)
{
this.Top = i;
Application.DoEvents();
}
state = 0;
}
}

private void Form1_MouseLeave(object sender, EventArgs e)
{
if (this.Top <= 0 && state==0)
{
state = 1;
int t=this.Top;
for (int i = t; i > -this.Height + 10; i--)
{
this.Top = i;
Application.DoEvents();
}
state = 0;
}
}
}
}

回答2:

private void Form5_Load(object sender, EventArgs e)
{
int x = SystemInformation.PrimaryMonitorSize.Width - this.Width;
int y= SystemInformation.PrimaryMonitorSize.Height - this.Height;//要让窗仿誉体往上走 只需游仔改变 Y的坐标神大汪
this.Location = new Point(x, y);
this.TopMost = true;
}

回答3:

private void Form2_Load(object sender, EventArgs e)
{
this.Left = 1000;

this.Top = 0;
}
类似的,不过你要获取分辨率

分辨率的话

Rectangle rect = new Rectangle();
rect = Screen.GetWorkingArea(this);
MessageBox.Show("本机器的分乎核辨率是"慎郑 + rect.Width.ToString() + "*" + rect.Height.ToString());
类似的就岁孝掘可以获取

回答4:

this.ControlBox = false;
或者
this.FormBorderStyle = FormBorderStyle.None;