Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

c# - Can't locate form to top right corner

I want to build a Windows Form Application using C# via Visual Studio Code manually. I want to locate my form to top right, so i create a variable of ScreenWidth and FormWidth:

int ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
int FormWidth1 = this.Size.Width;
int FormWidth2 = this.ClientSize.Width;

And the form properties:

this.Text = "Test";
this.Font = new Font("Comic Sans MS", 9, FontStyle.Bold);
this.BackColor = System.Drawing.Color.White;
this.WindowState = FormWindowState.Normal;
this.ClientSize = new Size(200, 400);
this.AutoScaleMode = AutoScaleMode.Dpi;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowInTaskbar = false;
this.TopMost = true;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(ScreenWidth - FormWidth1, 0);
this.FormBorderStyle = FormBorderStyle.None;
this.ResumeLayout(false);
this.PerformLayout();

But when i run the program, it is not located on the corner. So, i create a label that show my form width.

this.Label01.Text = FormWidth1.ToString();
this.Label02.Text = FormWidth2.ToString();

And it shows 284 and 300. I don't know what's the problem. I've tried to change the ClientSize, but it is same as before. I've tried to add:

this.Size = new Size(200,400);

And the result is not changed. This is the result. It's not on the corner. Please anyone help me to solve it. Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...