HOWTO设置典型C#/ Win-Forms应用程序的应用程序。 [英] HOWTO Set Applicationsize of typical C#/Win-Forms app.

查看:74
本文介绍了HOWTO设置典型C#/ Win-Forms应用程序的应用程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙,


我有一个典型的Win-Form应用程序,我在"调整大小"中发出这个简单的命令。句柄:


this.Width = 156;


但是,尽管成功运行,但是窗口大小达到了142像素。 />
同样,我尝试使用宽度:


this.Width = 586;


宽度达到572像素在宽度。这意味着,尽管"this.Width",使用时,它可以随意调整应用程序的窗口大小,例如应用程序窗口内的客户端宽度,和/或每次减去14
像素。


确实,它是前者。我会说,我需要根据需要设置宽度(以像素为单位),如果有任何形状边框,或者C#/ .NET中某些深度隐藏的Wind-Form gui覆盖了我对"thi.Width"的调用。 ,然后解决方案将需要
停用极端偏见。



解决方案

你好JSB,


我已经建立了一个简单的项目进行测试,样本有两个按钮和一个文本框。一个按钮用于调整宽度,另一个用于显示窗体的宽度。


我测试了很多,方法效果很好。


代码:

 int setWidth = 0; 
private void button1_Click(object sender,EventArgs e)
{
this.Width = int.Parse(textBox1.Text);
setWidth = int.Parse(textBox1.Text);
}
private void Form1_Resize(object sender,EventArgs e)
{
this.Width = setWidth == 0? this.Width:setWidth;
}
private void button2_Click(object sender,EventArgs e)
{
this.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; //得到应用程序的piex表单屏幕
MessageBox.Show(" Width:" + this.Width.ToString()+",Pix:" + Width.ToString());
}

屏幕截图:




我认为您的问题是由resize方法或覆盖事件引起的。你能提供一份重现样本吗?我将对其进行测试并尝试解决您的问题。


感谢您的理解。


问候,


月光


Please help,

I have a typical Win-Form app, and I issue this simple command in the "Resize" handle:

this.Width = 156;

But, despite this getting ran, successfully, the windows size comes out to 142 pixels.
Likewise, I tried this with width:

this.Width = 586;

And the width comes out to 572 pixels in width. This means, despite "this.Width" being used, it is either arbitrarily NOT sizing the application's window, like maybe the client width inside the application's window, and/or it is subtracting 14 pixels off every time.

Assuredly, it is the former. I will say, that I need to set the width in pixels as I need it, and if anything like form-border, or some deeply hidden Wind-Form gui in C#/.NET is overriding my call to "thi.Width", then the solution will need to deactivate that with extreme prejudice.

解决方案

Hi J-S-B,

I have built a simple project to test, the sample has two buttons and one textbox. One button use to resize the width, the other use to show the form's width.

I tested a lot and the method works well.

Code:

        int setWidth = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            this.Width = int.Parse(textBox1.Text);
            setWidth = int.Parse(textBox1.Text);
        }
        private void Form1_Resize(object sender, EventArgs e)
        {
            this.Width = setWidth == 0 ? this.Width : setWidth;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;//get the application's piex form screen
            MessageBox.Show("Width:" + this.Width.ToString() + ",Pix:" + Width.ToString());
        }

Screenshots:

I suppose your issue is cause by the resize methods or override event. Could you please provide a reproduce sample? I will test it and try to solve your issue.

Thanks for your understanding.

Regards,

Moonlight


这篇关于HOWTO设置典型C#/ Win-Forms应用程序的应用程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆