解释一下`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制作出一个矩形了。收获还是不错滴。。
虽然最后那个有点小瑕疵,,,,,不过没关系啦,哈哈。
第一个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)); } } }
虽然最后那个有点小瑕疵,,,,,不过没关系啦,哈哈。
相关文章推荐
- 如何通俗地解释一下 TCP/UDP 协议和 HTTP、FTP、SMTP 等协议之间的区别?
- Page.ClientScript.RegisterStartupScript 与 Page.ClientScript.RegisterClientScriptBlock 之间的区别
- scrollWidth,clientWidth与offsetWidth的区别
- Javascript:scrollWidth,clientWidth,offsetWidth的区别
- Height、offsetWidth、ClientHeight 区别
- 四种浏览器对 clientHeight、offsetHeight、scrollHeight、clientWidth、offsetWidth 和 scrollWidth 的解释差异
- this.clientWidth和this.offsetWidth两个有什么不同
- explicitWidth与width,和用setActualSize()方法有什么区别?
- explicitWidth与width,和用setActualSize()方法有什么区别?
- scrollWidth,clientWidth与offsetWidth的区别
- 简单地解释一下应用程序/代理进程和交易之间的关系
- scrollWidth,clientWidth与offsetWidth的区别
- scrollWidth,clientWidth与offsetWidth的区别
- 图示offsetWidth clientWidth scrollWidth scrollTop scrollLeft等属性的细微区别
- js中常用元素属性scrollLeft,scrollWidth,clientWidth,offsetWidth的解释
- 使用较大的 JavaScript 函数(3)---Page.ClientScript.RegisterStartupScript 与 Page.ClientScript.RegisterClientScriptBlock 之间的区别
- scrollWidth,clientWidth等区别
- style.left,offsetLeft,scrollLeft和clientLeft之间的区别(未完待续)
- [转]PHP中 this,self,parent三个关键字之间的区别
- Height、offsetWidth、ClientHeight 区别