控制问题的对中计算 [英] Centering calculation for control problem

查看:131
本文介绍了控制问题的对中计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在父矩形底部中心的另一个矩形上绘制一个矩形.我使用了一些我认为可以正常工作的非常基本的代码,但它根本不显示子矩形,我称之为bottomconnector.以下是我的一些代码"

I am trying to draw a rectangle on another rectangle on the bottom center of the parent rectangle. I am using some very basic code that I thought would work but it does not display the child rectangle at all I called bottomconnector. Below is some of my code"

[Browsable(false)]
public Rectangle BottomConnector
{
   get
   {
        return new Rectangle(this.ClientRectangle.Width / 2, this.ClientRectangle.Bottom, 30, 30)
   }
}



然后在我的onpaint覆盖中,我还有其他代码,但这是我用于此连接器矩形的内容.



Then in my onpaint override I have other code but this is what I used for this connector rectangle.

// Draw Bottom Connector
g.FillRectangle(new SolidBrush(this.TitleBarColor), this.BottomConnector);



我对职位的计算可能有问题,但我看不出我在搞什么.感谢任何人对此的帮助!

TheChazm



It may be a problem with my calculation for the position but I just don''t see where I am messing up at. Thanks for anyone''s help on this!

TheChazm

推荐答案

尝试一下:

Try this:

return new Rectangle((this.ClientRectangle.Width / 2) - 15, this.ClientRectangle.Bottom - 30, 30, 30)



按照您的操作方式,新矩形的顶部从第一个矩形的确切底部开始,因此在绘制时,它位于第一个矩形的下面,因此您看不到它.

-15部分将其居中于矩形的中心.基本上是newWidth/2.



They way you were doing it, the top of the new rectangle starts at the exact bottom of the first one, so when it draw, it goes below the bottom of the first, making it so you can''t see it.

The -15 part is to center it in the center of the rectangle. Basically newWidth / 2.


这篇关于控制问题的对中计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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