2 Replies - 1648 Views - Last Post: 02 October 2016 - 02:03 PM Rate Topic: -----

#1 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 10-August 12

create a custom label with BorderColor property

Posted 02 October 2016 - 01:16 AM

hi friends
I try to create a label with BorderColor property.but it not work . I create an instant object of this label in my form application and try to change the BorderColor , but nothing is happen.
this is my code :

Public Class MyLabel
    Inherits Label

    Private _BorderColor As Color
    Private _BorderSize As Single = 1.0F
    Dim e As New PaintEventArgs(Me.CreateGraphics, Me.DisplayRectangle)

    Public Property BorderColor As Color
        Get
            Return _BorderColor
        End Get
        Set(value As Color)
            _BorderColor = value
            CreateBorder(value)
        End Set
    End Property

    Private Sub CreateBorder(ByVal value As Color)
        Dim g As Graphics = Me.CreateGraphics
        Dim p As Pen = New Pen(value, 2)
        g.DrawRectangle(p, Me.DisplayRectangle)
    End Sub

    Private Sub MyLabel_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        CreateBorder(_BorderColor)
    End Sub
End Class

This post has been edited by pooya1072: 02 October 2016 - 01:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: create a custom label with BorderColor property

#2 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6343
  • View blog
  • Posts: 25,601
  • Joined: 12-December 12

Re: create a custom label with BorderColor property

Posted 02 October 2016 - 10:43 AM

Question moved out of Discussion Lounge. You are seeking help not initiated a discussion.
Was This Post Helpful? 1
  • +
  • -

#3 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1435
  • View blog
  • Posts: 3,661
  • Joined: 01-February 13

Re: create a custom label with BorderColor property

Posted 02 October 2016 - 02:03 PM

Please see the example that Viorel gave you on Msdn (link below).
create a custom label with BorderColor property

As a side note, any Pens, Graphics, Brushes, exc. objects that you create in your code, you are also responsible for Disposing when they are no longer needed. Also, you would want to do all your drawing in the OnPaint overrides sub as Viorel showen you. You should be using the e.Graphics object passed to that sub to draw onto the Label, don`t create a new graphics object of the Label.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1