首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DrawRectangle超出了形式界限

DrawRectangle超出了形式界限
EN

Stack Overflow用户
提问于 2015-09-06 12:17:19
回答 1查看 327关注 0票数 0
代码语言:javascript
运行
复制
private void Form1_Paint(object sender, PaintEventArgs e)
    {
        g = e.Graphics;
        blockList.DrawBlocksInList(g);  //Drawing the blocks that were added to the list in the Form1_Load below;
        g.FillRectangle(MainBlock._Pen.Brush, MainBlock._Rectangle);  //Drawing the Main Block;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        float rectSize = this.Width / 10.0f;    //What the size of each rectangle should be, depending on the form's size;
        Block BlockForList; //No need to initialize it;
        for (float y = 0; y < this.Height; y += rectSize)   //500 is the size of the Form, 50 is the size of the X & Y of each rectangle;
            for (float x = 0; x < this.Width; x += rectSize)
            {
                BlockForList = new Block(pen, new RectangleF(x, y, rectSize, rectSize)); //Initializing the block each time to set different locations;
                blockList.list.Add(BlockForList);   //Adding the blocks to the list to draw them all;
            }
    }

之后,我使用一个方法来绘制blockList.list中的所有块,但是会发生这样的情况:http://imgur.com/5h7ZMTH

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-06 12:31:56

当然,它将超出界限--您已经告诉它,允许每个块的左边沿上升到Width,并允许右边缘上升到Height

您是想要这个吗?

代码语言:javascript
运行
复制
    for (float y = 0; y < this.Height-rectSize; y += rectSize)   //500 is the size of the Form (this.Width & this.Height), 50 (rectSize) is the size of the X & Y of each rectangle (basically squares);
        for (float x = 0; x < this.Width-rectSize; x += rectSize)

--

编辑

同样在油漆中,您首先需要调用base OnPaint()方法。这将填补背景。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32423475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档