专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

请教一个圆角矩形的有关问题

发布时间:2011-06-23 15:56:22 文章来源:www.iduyao.cn 采编人员:星星草
请问一个圆角矩形的问题。
这是一个获取圆角的的函数:
        Public   Shared   Function   get圆角矩形(ByVal   rec   As   Rectangle,   ByVal   r   As   Integer)   As   Drawing2D.GraphicsPath
                Dim   gp   As   New   Drawing2D.GraphicsPath
                gp.AddLine(rec.Left   +   r,   rec.Top,   rec.Right   -   r,   rec.Top)   '上
                gp.AddArc(rec.Right   -   r   *   2,   rec.Top,   r   *   2,   r   *   2,   270,   90)   '右上
                gp.AddLine(rec.Right,   rec.Top   +   r,   rec.Right,   rec.Bottom   -   r)   '右
                gp.AddArc(rec.Right   -   r   *   2,   rec.Bottom   -   r   *   2,   r   *   2,   r   *   2,   0,   90)   '右下
                gp.AddLine(rec.Right   -   r,   rec.Bottom,   rec.Left   +   r,   rec.Bottom)   '下
                gp.AddArc(rec.Left,   rec.Bottom   -   r   *   2,   r   *   2,   r   *   2,   90,   90)   '左下
                gp.AddLine(rec.Left,   rec.Bottom   -   r,   rec.Left,   rec.Top   +   r)   '左
                gp.AddArc(rec.Left,   rec.Top,   r   *   2,   r   *   2,   180,   90)   '左上
                gp.CloseFigure()

                Return   gp

使用时:
        Protected   Overrides   Sub   OnPaint(ByVal   e   As   System.Windows.Forms.PaintEventArgs)
                MyBase.OnPaint(e)

                Dim   rec   As   New   Rectangle(20,   20,   100,   60)
                Dim   gp   As   Drawing2D.GraphicsPath   =   Form1.get圆角矩形(rec,   4)
                e.Graphics.FillPath(Brushes.Red,   gp)

        End   Sub


四个角的大小并不一致,特别是当半径小于6左右时,很明显。
请高手指点一下好吗?


------解决方案--------------------
使用 点 的误差问题吧



------解决方案--------------------
误差,没办法,就像在特定分辨率下的圆永远化不圆(不连续,类似下面的效果)
--
-- --
-- --


Public Shared Function get圆角矩形(ByVal rec As Rectangle, ByVal r As Integer) As Drawing2D.GraphicsPath
Dim gp As New Drawing2D.GraphicsPath
gp.AddLine(rec.Left + r, rec.Top, rec.Right - r, rec.Top) '上
gp.AddArc(rec.Right - r * 2, rec.Top, r * 2, r * 2, 270, 90) '右上
gp.AddLine(rec.Right, rec.Top + r, rec.Right, rec.Bottom - r) '右
gp.AddArc(rec.Right - r * 2, rec.Bottom - r * 2, r * 2, r * 2, 0, 90) '右下
gp.AddLine(rec.Right - r, rec.Bottom, rec.Left + r, rec.Bottom) '下
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: