如何设置winform起始位置在右上角?

发布于 2024-12-12 00:50:46 字数 91 浏览 0 评论 0原文

如何设置winform起始位置在右上角?我的意思是,当用户单击(启动)我的 winform 应用程序时,winform 将出现在屏幕的右上角?

How to set winform start position at top right? I mean when user click (start) my winform application the winform will appear at the top right of the screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

八巷 2024-12-19 00:50:47

使用 Load 事件更改位置,在应用用户首选项和自动缩放后,您最早会知道窗口的实际大小:

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.FromPoint(Me.Location)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class

Use the Load event to change the position, the earliest you'll know the actual size of the window after user preferences and automatic scaling are applied:

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.FromPoint(Me.Location)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class
彼岸花似海 2024-12-19 00:50:47

在表单加载中,甚至将窗口位置发送到 y=0 和 x= 屏幕宽度 - 表单宽度。

例如,

private void Form1_Load(object sender, EventArgs e)
{
  this.Location = new Point( Screen.PrimaryScreen.Bounds.Right - this.Width,0);
}

您也可以使用“Screen.GetBounds(this).Right”。这将为您提供包含表单的屏幕坐标。

In form load even send the windows position to y=0 and x= Screen width - form width.

e.g.

private void Form1_Load(object sender, EventArgs e)
{
  this.Location = new Point( Screen.PrimaryScreen.Bounds.Right - this.Width,0);
}

You can alternatively use "Screen.GetBounds(this).Right". This will give you the coordinates of screen which contain your form.

神妖 2024-12-19 00:50:47

您可以使用 Form.Location 将位置设置为表示表单左上角的点。

因此,如果您将其设置为“屏幕宽度 - 表单宽度”,您可以将表单放置在右上角。
要获取屏幕宽度,您可以使用屏幕。边界 属性。

You can use Form.Location to set the location to a Point that represents the top left corner of the form.

So if you set this to 'Screenwidth - Formwidth' you can position the Form in the top right.
To get the screen width you can use the Screen.Bounds property.

残花月 2024-12-19 00:50:47

frm.Designer.cs 文件中添加代码行

this.Location = new Point(0,0);

注意:
检查该位置是否已在 frm.resX 文件中设置,您可以在那里更改它。
或者从 .resX 文件中删除并在 frm.Designer.cs 中添加以上

行,任何方式都可以。

Add the line of code in frm.Designer.cs file

this.Location = new Point(0,0);

Note:
Check if the location is already set in frm.resX file you can change it there.
Or remove from .resX file and add the above line in frm.Designer.cs

Any way it will work.

岛徒 2024-12-19 00:50:47

如果您有多显示器,则显示在主显示器上 对于多显示器设置有用

从右上角开始

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.AllScreens(0)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class

从左上角开始

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.AllScreens(0)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width - scr.WorkingArea.Right + Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class

to show on the primary monitor if you have multi monitor useful for multi monitor setup

Start on Upper Right

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.AllScreens(0)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class

Start on Upper Left

Public Class Form1
    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim scr = Screen.AllScreens(0)
        Me.Location = New Point(scr.WorkingArea.Right - Me.Width - scr.WorkingArea.Right + Me.Width, scr.WorkingArea.Top)
        MyBase.OnLoad(e)
    End Sub
End Class
述情 2024-12-19 00:50:47

只需将其添加到您的 OnLoad 事件中即可

    Me.Location = New Point(1, 1)  

Just Add This to your OnLoad Event

    Me.Location = New Point(1, 1)  
亣腦蒛氧 2024-12-19 00:50:47

您可以在表单的 OnLoad 事件中使用它

 private void dlgTTMSContract_Load(object sender, EventArgs e) {
   int screenWidth = Screen.PrimaryScreen.Bounds.Size.Width;
   int formWidth = this.Width;
   this.Location = new Point(screenWidth - formWidth, 0);
 }

you can use this in OnLoad Event of your Form

 private void dlgTTMSContract_Load(object sender, EventArgs e) {
   int screenWidth = Screen.PrimaryScreen.Bounds.Size.Width;
   int formWidth = this.Width;
   this.Location = new Point(screenWidth - formWidth, 0);
 }
<逆流佳人身旁 2024-12-19 00:50:47

它对你来说效果很好:

private void Form1_Load(object sender, EventArgs e)
        {
            this.Location = new Point(Screen.FromPoint(this.Location).WorkingArea.Right - this.Width, 0);
        }

It works fine for you:

private void Form1_Load(object sender, EventArgs e)
        {
            this.Location = new Point(Screen.FromPoint(this.Location).WorkingArea.Right - this.Width, 0);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文