2016-06-17 66 views
0

我有一个C#winforms,其中我绘制一个矩形,然后填充它。C#填充矩形留下一个空白区域

下面是代码:

LinearGradientBrush secondGradient = new LinearGradientBrush(frontRect, Color.FromArgb(255, 190, 171, 18), Color.FromArgb(255, 152, 186, 27), 90); 

    /* second row element */ 
        g.DrawRectangle(pen, leftInsertionBox); 
        g.FillRectangle(secondGradient, leftInsertionBox.X + 1, leftInsertionBox.Y + 1, leftInsertionBox.Width - 1, leftInsertionBox.Height - 1); 

        g.DrawRectangle(pen, leftCoverBox); 
        g.FillRectangle(secondGradient, leftCoverBox.X + 1, leftCoverBox.Y + 1, leftCoverBox.Width - 1, leftCoverBox.Height - 1); 
        /* second row element */ 

的问题是,我可以看到像我的矩形线条和填充之间的空白像素。

enter image description here

如何解决这个任何线索?

+1

首先'Fill'整个矩形(删除+1的偏移量),然后'Draw' –

+0

我看不到图像,因为imgur被阻止我,但你有一个SolidBrush尝试过吗? – hometoast

+0

你有没有尝试以相反的顺序进行操作?我试着做填充,没有任何偏移量计算(即填充整个矩形),然后绘制边界。 – itsme86

回答

1

我会尝试扭转操作。先进行填充操作,删除偏移量计算(即填充整个区域),然后绘制边界。

g.FillRectangle(secondGradient, leftInsertionBox.X, leftInsertionBox.Y, leftInsertionBox.Width, leftInsertionBox.Height); 
g.DrawRectangle(pen, leftInsertionBox); 

g.FillRectangle(secondGradient, leftCoverBox.X, leftCoverBox.Y, leftCoverBox.Width, leftCoverBox.Height); 
g.DrawRectangle(pen, leftCoverBox); 
0

尝试删除您添加的额外像素。

相关问题