.net - Custom Control Text Missing -


i have custom control supposed represent label, rounded corners. i've created control drag , drop designer toolbox, rounded top corners, text seems dissapear.

i know can add custom property text show @ bottom, text property there , ideally use it. thought using override property, @ minute still doesn't show.

any suggestions, i've copied code below...

imports system.windows.forms.design imports system.runtime.interopservices imports system.drawing.drawing2d imports system.componentmodel  public class customcontrol     inherits system.windows.forms.usercontrol     private m_radius integer     private m_borderwidth integer     private m_fillcolor color     private m_text string = me.text     private m_label label      private components system.componentmodel.container = nothing      public sub new()          mybase.borderstyle = windows.forms.borderstyle.none     end sub       ''' <summary>     ''' indicates radius of control's corners     ''' </summary>     ''' <returns>the corner radius.</returns>     public property radius integer                     return m_radius         end         set(value integer)             m_radius = value         end set     end property      ''' <summary>     ''' indicates width draw outer border of control.     ''' </summary>     ''' <returns>the border width.</returns>     public property borderwidth integer                     return m_borderwidth         end         set(value integer)             m_borderwidth = value         end set     end property      ''' <summary>     ''' indicates outline colour of control.     ''' </summary>     ''' <returns>the outline colour.</returns>     public property fillcolor color                     return m_fillcolor         end         set(value color)             m_fillcolor = value         end set     end property      <browsable(true), designerserializationvisibility(designerserializationvisibility.visible)> _     overrides property text() string                     return m_text         end         set(byval value string)             m_text = value             'this line update             'the ui when design check             'if values saved.             mybase.text = value         end set     end property       protected overrides sub onpaint(e painteventargs)         dim rect rectangle = me.clientrectangle 'drawing rounded rectangle         rect.x = rect.x + 1         rect.y = rect.y + 1         rect.width -= 2         rect.height -= 2          using bb graphicspath = getpath(rect, radius)             'draw background             using br brush = new solidbrush(fillcolor)                 e.graphics.smoothingmode = smoothingmode.highquality                 e.graphics.interpolationmode = interpolationmode.highqualitybilinear                 e.graphics.fillpath(br, bb)             end using             'draw border             using br brush = new solidbrush(color.black)                 rect.inflate(-1, -1)                 e.graphics.smoothingmode = smoothingmode.highquality                 e.graphics.interpolationmode = interpolationmode.highqualitybilinear                 e.graphics.drawpath(new pen(br, borderwidth), bb)             end using         end using     end sub      protected function getpath(byval rc rectangle, byval r int32) graphicspath         dim x int32 = rc.x, y int32 = rc.y, w int32 = rc.width - 1, h int32 = rc.height - 1         r = r << 1         dim path graphicspath = new graphicspath()         if r > 0             if (r > h) r = h             if (r > w) r = w              ' top left             path.addarc(x, y, r, r, 180, 90)              ' top right             path.addarc(x + w - r, y, r, r, 270, 90)              'bottom right             'path.addarc(x + w - r, y + h - r, r, r, 0, 90)             path.addline(x + w, y + h, x + w, y + h)              ' bottom left             ' path.addarc(x, y + h - r, r, r, 90, 90)             path.addline(x, y + h, x, y + h)              path.closefigure()         else             path.addrectangle(rc)         end if         return path     end function  end class 

thanks

you drawing borders in onpaint override , not text. @ bottom add:

textrenderer.drawtext(e.graphics, m_text, me.font,                       new point(3, 3), me.forecolor) 

this draws fixed point 3,3, may want add code calculate location based on textalign property (todo) or @ least based on padding values.

if want redraw text @ design time when change it, you'll have add me.invalidate() text property setter.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -