您的位置:首页 > 其它

解释一下`this.Width` 和 `this.ClientRectangle.Width` 和 `this.ClientSize.Width`之间的区别

2016-10-12 18:01 447 查看
哎呀,这不是为难我吗?不过在大脑出现了短暂性的空白加迷茫后还是默默的想起那一丝丝的记忆,决定还是在bibi几句为好,这会bibi些啥我就不敢保障了,哈哈。。。

第一个this.width只得是这个控件的宽度,而并非不是this.clientrectangle.width所表示的控件工作区的宽度。因为不知道控件的宽度和你所要运行工作区的宽度间的距离,所以改为工作区的宽度后不会出现 工作物在弹来弹去的过程中超出了一点点的边界。。

而这个this。clientsize.width,是为了获取或设置这个工作区高度和长度。额,他的属性是表示控件工作区的维数。好像大概就知道这点意思吧。。。。额,不过暂时还不知后两者的区别。。。。。

不过倒是学会了如何表示坐标的书写格式,限定控件运行的范围,以及用pen制作出一个矩形了。收获还是不错滴。。

namespace WindowsFormsApplication1.number5
{
public partial class Form1 : Form
{
int ox,oy;
int a = 20;

public Form1()
{
ox = 1;
oy = 1;
InitializeComponent();
label1.Text = "你好";
button1.Text = "我不好";
}

private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black);
g.DrawRectangle(p, 20, 20, this.ClientSize.Width -40,150 );
Rectangle rect = new Rectangle(20, 20, this.ClientSize.Width - 40, 150);
g.DrawRectangle(p,rect);

p.Dispose();
g.Dispose();
if (
timer1.Enabled)
timer1.Stop();
else
timer1.Start();
label1.Text = "那我走了";
button1.Text = "走一下试试";
label2.Text ="(" + "20" + "  " + "20)";
label3.Text = "(" + (this.ClientSize.Width - 40).ToString() + "  " + "20)";
label4.Text =  "("+(this.ClientSize.Width - 40).ToString() + "  " + "170)";
label5.Text = "(20" + "  " + "170)";

}

private void timer1_Tick(object sender, EventArgs e)
{
Random b = new Random();

//up
if (oy == -1 &&
label1.Location.Y < a)
oy = 1;

//right
if ((label1.Location.X + label1.Width > (this.ClientSize.Width - 20)) && ox == 1)
ox = -1;

//down
if ((label1.Location.Y + this.label1.Height > 170) && oy == 1)
oy = -1;

if (label1.Location.X < a && ox == -1)
ox = 1;

label1.Location = new Point(label1.Location.X + ox * b.Next(10), label1.Location.Y + oy * b
.Next(10));

}

}
}


虽然最后那个有点小瑕疵,,,,,不过没关系啦,哈哈。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  解释