开发者

Drawing complex shapes onto a form. (.net)

开发者 https://www.devze.com 2023-02-18 10:40 出处:网络
I have a control that looks similar to the following: I need to add slightly round ends where all that extra end space is.I\'m not sure how to add these.It sho开发者_如何学Pythonuld look similar to

I have a control that looks similar to the following:

Drawing complex shapes onto a form. (.net)

I need to add slightly round ends where all that extra end space is. I'm not sure how to add these. It sho开发者_如何学Pythonuld look similar to the round ends on this page. (At the top)

Thanks!


A few years late ... but this may be the answer to your question.

Public Sub DrawRoundedRectangle(ByVal objGraphics As Graphics, _
                                ByVal m_intxAxis As Integer, _
                                ByVal m_intyAxis As Integer, _
                                ByVal m_intWidth As Integer, _
                                ByVal m_intHeight As Integer, _
                                ByVal m_diameter As Integer)



   'Dim g As Graphics
    Dim BaseRect As New RectangleF(m_intxAxis, m_intyAxis, m_intWidth, 
                                  m_intHeight)
    Dim ArcRect As New RectangleF(BaseRect.Location,
                              New SizeF(m_diameter, m_diameter))
    'top left Arc
    objGraphics.DrawArc(Pens.Black, ArcRect, 180, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + CInt(m_diameter / 2), 
                         m_intyAxis, 
                         m_intxAxis + m_intWidth - CInt(m_diameter / 2), 
                         m_intyAxis)

    ' top right arc
    ArcRect.X = BaseRect.Right - m_diameter
    objGraphics.DrawArc(Pens.Black, ArcRect, 270, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + m_intWidth, 
                         m_intyAxis + CInt(m_diameter / 2), 
                         m_intxAxis + m_intWidth, 
                         m_intyAxis + m_intHeight - CInt(m_diameter / 2))

    ' bottom right arc
    ArcRect.Y = BaseRect.Bottom - m_diameter
    objGraphics.DrawArc(Pens.Black, ArcRect, 0, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + CInt(m_diameter / 2), 
                         m_intyAxis + m_intHeight, 
                         m_intxAxis + m_intWidth - CInt(m_diameter / 2), 
                         m_intyAxis + m_intHeight)

    ' bottom left arc
    ArcRect.X = BaseRect.Left
    objGraphics.DrawArc(Pens.Black, ArcRect, 90, 90)
    objGraphics.DrawLine(Pens.Black, 
                         m_intxAxis, m_intyAxis + CInt(m_diameter / 2), 
                         m_intxAxis, 
                         m_intyAxis + m_intHeight - CInt(m_diameter / 2))

End Sub

Provide the parameters from your code to draw the rectangles and away you are!

0

精彩评论

暂无评论...
验证码 换一张
取 消