Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectangle behind it?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Resolved [RESOLVED] rounded corner label test look terrible, can we get rid of the rectangle behind it?

    And I told it to have a yellow back color, but it has done something else, yellow showing in the rectangle and ugly brownish elsewhere.

    I thought the rounded label control would not display any rectangular view?

    https://learn.microsoft.com/en-us/do...orms-controls?

    Here is the user control code

    Code:
    Imports System.Drawing.Drawing2D
    'https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-inherit-from-existing-windows-forms-controls?view=netframeworkdesktop-4.8
    
    Public Class UserControl1
        Inherits System.Windows.Forms.Label
    
        Private _radius As Int32 = 20     'Radius of the Corner Curve
        Private _opacity As Int32 = 125   'Opacity of the Control
        Private _backColor As System.Drawing.Color = Color.Black 'Back Color of Control
    
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            rect.X = rect.X + 1
            rect.Y = rect.Y + 1
            rect.Width -= 2
            rect.Height -= 2
            Using bb As GraphicsPath = GetPath(rect, _radius)
                Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                    e.Graphics.FillPath(br, bb)
                End Using
            End Using
        End Sub
        'Returns the GraphicsPath to Draw a RoundedRectangle
        Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
            Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
            r = r << 1
            Dim path As GraphicsPath = New GraphicsPath()
            If r > 0 Then
                If (r > h) Then r = h
                If (r > w) Then r = w
                path.AddArc(x, y, r, r, 180, 90)
                path.AddArc(x + w - r, y, r, r, 270, 90)
                path.AddArc(x + w - r, y + h - r, r, r, 0, 90)
                path.AddArc(x, y + h - r, r, r, 90, 90)
                path.CloseFigure()
            Else
                path.AddRectangle(rc)
            End If
            Return path
        End Function
    End Class
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Change like this,

    Private _backColor As System.Drawing.Color = Color.Yellow

    Creates an entire rectangular label, no rounded corners show.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Well, vs2022 just stopped responding, crashed, restarted, and reloaded the project.
    Have not seen that in a while, it must not like the user control?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,600

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    You need to set the Region property to the same area that you are colouring.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,600

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    You may also be interested in this, which provides a possibly superior option.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    This is how to reshape a control…

    Code:
    Public Sub New()
        Me.Region = New Region(GetPath(rect, _radius))
    End Sub

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    I first found this code on the web, then found it here with some additional region coding

    https://www.vbforums.com/showthread....-label-control

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by .paul. View Post
    This is how to reshape a control…

    Code:
    Public Sub New()
        Me.Region = New Region(GetPath(rect, _radius))
    End Sub
    Will look into it thanks.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by jmcilhinney View Post
    You may also be interested in this, which provides a possibly superior option.
    Ok, will check it, thanks

    If I figure out something good looking, will post it here.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    This am looking into the rounded label idea.
    Made more progress than I thought I could, but seems to not be aligned well?
    Added a region statement

    I draw a red outline and a blue background
    The red should go all round the blue but does not.

    Any ideas how to fix that?

    Is in the paint event?


    Complete user control so far.
    Code:
    Imports System.Drawing.Drawing2D
    'https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-inherit-from-existing-windows-forms-controls?view=netframeworkdesktop-4.8
    Public Class UserControl1
        Inherits System.Windows.Forms.Label
    
        Private _radius As Int32 = 20     'Radius of the Corner Curve
        Private _opacity As Int32 = 125   'Opacity of the Control
        Private _backColor As Color = Color.Blue 'Back Color of Control
    
    
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            '  https://learn.microsoft.com/en-us/dotnet/api/system.drawing.region.-ctor?view=net-8.0
    
    
    
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            rect.X = rect.X + 1
            rect.Y = rect.Y + 1
            rect.Width -= 4
            rect.Height -= 4
            Using bb As GraphicsPath = GetPath(rect, _radius)
    
                e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 2), bb)
    
                Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                    e.Graphics.FillPath(br, bb)
                End Using
    
    
    
    
                Dim Region As New Region(bb)
                Me.Region = Region
    
            End Using
        End Sub
        'Returns the GraphicsPath to Draw a RoundedRectangle
        Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
            Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
            r = r << 1
            Dim path As GraphicsPath = New GraphicsPath()
    
    
            If r > 0 Then
                If (r > h) Then r = h
                If (r > w) Then r = w
    
                path.StartFigure()
                '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)
                'bottom left
                path.AddArc(x, y + h - r, r, r, 90, 90)
    
                path.CloseFigure()
            Else
                path.AddRectangle(rc)
            End If
            Return path
        End Function
    End Class
    Attached Images Attached Images  

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Plus would like to know why the green round label using a different method is so badly shaped?

    Done this way, put label50 on a form

    In form load this

    Code:
         Dim gp As GraphicsPath = GetPath(Label50.ClientRectangle, 20)
         Label50.Region = New Region(gp)
         Label50.BackColor = Color.Green
    Which is running this and I can't make it look right as only some of the corners are somewhat roundish.

    Code:
       Private Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
           Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
           r = r << 1
           Dim path As New GraphicsPath
    
    
           If r > 0 Then
               path.StartFigure()
               If (r > h) Then r = h
               If (r > w) Then r = w
    
               path.StartFigure()
               '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)
               'bottom left
               path.AddArc(x, y + h - r, r, r, 90, 90)
    
               path.CloseFigure()
    
           Else
               path.AddRectangle(rc)
           End If
           Return path
       End Function
    Attached Images Attached Images  

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    This mod makes it look a little better, still the left corner is more heavily showing the red line.
    The thickness I changed from 2 to 4, corner radius to 30
    And paint the red line after filling region with blue


    Also playing with elliptical buttons but the edges are not very smooth

    Code:
      Private _radius As Int32 = 30    'Radius of the Corner Curve
    Code:
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            '  https://learn.microsoft.com/en-us/dotnet/api/system.drawing.region.-ctor?view=net-8.0
    
    
    
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            'rect.X = rect.X ' - 10
            'rect.Y = rect.Y '- 10
            'rect.Width -= 2
            'rect.Height -= 2
            Using bb As GraphicsPath = GetPath(rect, _radius)
                Using Region As New Region(bb)
                    Me.Region = Region
    
    
                    Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                        e.Graphics.FillPath(br, bb)
                    End Using
                    e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 4), bb)
                End Using
    
    
    
            End Using
        End Sub
    Attached Images Attached Images  

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    You should set the Region just once instead of every time your control repaints...

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i


  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by .paul. View Post
    You should set the Region just once instead of every time your control repaints...
    Is it repainting a lot of times?

    vs2022 was crashing a lot on this usercontrol.
    Then something strange, control refused to work any more and the image was painted with a big red exception.
    I deleted the usercontrol and grabbed another from toolbox.

    And this one is working, much better looking too, I find that totally unexplainable.

    Here is my updated code so far and what it looks like in the designer

    Code:
    Public Class UserControl1
        Inherits System.Windows.Forms.Label
    
        Private _radius As Int32 = 20     'Radius of the Corner Curve
        Private _opacity As Int32 = 125   'Opacity of the Control
        Private _backColor As Color = Color.Blue 'Back Color of Control
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            '  https://learn.microsoft.com/en-us/dotnet/api/system.drawing.region.-ctor?view=net-8.0
    
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            rect.X = rect.X + 1
            rect.Y = rect.Y + 1
            rect.Width -= 4
            rect.Height -= 4
            Using bb As GraphicsPath = GetPath(rect, _radius)
    
                Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                    e.Graphics.FillPath(br, bb)
                End Using
                e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 4), bb)
    
                Dim Region As New Region(bb)
                Me.Region = Region
    
            End Using
        End Sub
        'Returns the GraphicsPath to Draw a RoundedRectangle
        Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
            Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
            r = r << 1
            Dim path As GraphicsPath = New GraphicsPath()
    
    
            If r > 0 Then
                If (r > h) Then r = h
                If (r > w) Then r = w
    
                path.StartFigure()
                '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)
                'bottom left
                path.AddArc(x, y + h - r, r, r, 90, 90)
    
                path.CloseFigure()
            Else
                path.AddRectangle(rc)
            End If
            Return path
        End Function
    End Class
    Attached Images Attached Images  

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    It repaints thousands of times

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by .paul. View Post
    It repaints thousands of times
    I put a breakpoint on the Private Sub UserControl1_Paint sub, and it is only loading one time when frmlogon with the label loads.


    I then loaded another form with program running, clicked back on frmLogon, and it did not fire the Private Sub UserControl1_Paint sub routine.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    I put this in the usercontrol sub

    Debug.Print("Hello")

    then ran using F5, debugging, prints "Hello' only one time

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    This one will not set a fill color, that way can just set your own label back color in the designer, which is better.

    Border on this one is white, could be any rgb color, rim color thickness here set to 4

    I don't see paint executing more than once.
    Anyone has ideas, how to do it differently or better?

    In the designer it appears as it does when running. Make code changes to user control it changes how it appears in the designer.


    Code:
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            '  https://learn.microsoft.com/en-us/dotnet/api/system.drawing.region.-ctor?view=net-8.0
    
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            ' rect.X = rect.X + 1
            ' rect.Y = rect.Y + 1
            'rect.Width -= 4
            'rect.Height -= 4
    
            Debug.Print("Hello")
    
            Using bb As GraphicsPath = GetPath(rect, _radius)
    
                'Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                'e.Graphics.FillPath(br, bb)
                'End Using
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 4), bb) 'red
    
                e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 255, 255), 10), bb) 'white
    
                Dim Region As New Region(bb)
                Me.Region = Region
    
            End Using
        End Sub

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    If you simply do this for any named label, you can get rounded corners and green background

    Code:
        Private Sub frmLogon_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    
            Dim gp As GraphicsPath = GetPath(Label50.ClientRectangle, 20)
            Label50.Region = New Region(gp)
            Label50.BackColor = Color.Green
    Then this sub here makes the corners

    Code:
      Private Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
          Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
          r = r << 1
          Dim path As New GraphicsPath
    
          If r > 0 Then
              path.StartFigure()
              If (r > h) Then r = h
              If (r > w) Then r = w
    
              path.StartFigure()
    
              '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)
              'bottom left
              path.AddArc(x, y + h - r, r, r, 90, 90)
    
              path.CloseFigure()
    
          Else
              path.AddRectangle(rc)
          End If
    
          Return path
      End Function
    The right sided corners look less rounded than the left side.
    The text does not center well even though told to center in the label properties

    Fo some reason just looks not as good.

    Anyone know why?

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    picture of label50, the green label

    Right side corners are they different?

    Text not centered.

    EDIT, I found out the right side of label50 is running into the left side of the combo box causing the curve to flatten out.

    The resizer module can't properly resize the label50 green control text properly, so unless that can be dealt with, wont be using that label50 code outside of the usercontrol.

    added a picture that shows what happens to green label text versus yellow label text (the usercontrol) when form is super stretched
    Attached Images Attached Images   
    Last edited by sdowney1; Jun 22nd, 2024 at 05:09 AM.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    I have a resizer module that resizes all the 'controls'
    When I resize the form, the green label50 gets very messed up, text slides over and the corners do odd things.

    But the yellow usercontrol label resizes perfectly.
    Which means I will need to use the usercontrol If I want it to look good.

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Moved this code from form load to form resize and now it looks fine like the yellow label

    Means, you don't have to use a user control

    Any ideas how to draw the border outside the user control? Will look into it next.

    Code:
        Private Sub frmLogon_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize
            clsElastic.ResizeAllControls(Me)
            Dim gp As GraphicsPath = GetPath(Label50.ClientRectangle, 20)
            Label50.Region = New Region(gp)
            Label50.BackColor = Color.Green
    
        End Sub

  24. #24
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by sdowney1 View Post
    …But the yellow usercontrol label resizes perfectly.
    Which means I will need to use the usercontrol If I want it to look good.
    What is the advantage of not using an extended control? Encapsulation is the preferred and recommended OOP method.

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: rounded corner label test look terrible, can we get rid of the rectangle behind i

    Quote Originally Posted by .paul. View Post
    What is the advantage of not using an extended control? Encapsulation is the preferred and recommended OOP method.
    Just if you don't want to delete all your labels and start over is all I can think.
    You can just draw path the existing label.

    What I am wondering is how you can create a new property for a usercontrol?

    Like radius and color for the pen draw?

    Right now it is hard coded into the code right here

    Code:
    Public Class UserControlLabel
        Inherits System.Windows.Forms.Label
    
        Private _radius As Int32 = 10     'Radius of the Corner Curve
        ' Private _opacity As Int32 = 125   'Opacity of the Control
        'Private _backColor As Color = Color.Blue 'Back Color of Control
    And the PEN color is also hard coded.

    Code:
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 4), bb) 'red
                e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 255, 255), 5), bb) 'white
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 0, 0, 0), 10), bb) 'black
    I commented out backcolor as it is a label property in the usercontrol properties window, just set it as you wish outside the control
    But the radius and draw pen color, would be nice to set that some other way.


    I also renamed it to usercontrollabel

    And it can be tranparent and let an image shine through too.

    Here one is transparent and one is red

    I am also thinking I can use a transparent label as a frame using the draw pen, and have other labels grouped inside the frame
    The green label is not a usercontrol, just a get path radius corner modification of a normal label control with a different radius number.

    The other rounded controls are the usercontrol
    Attached Images Attached Images  

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    code to do that is this
    I also set backcolor to transparent in the property pages, it is listed under web colors.
    Code:
            'does work with user control, if set backcolor transparent (web color)
            'Dim position13 = Image1.PointToClient(UserControlLabel1.PointToScreen(Point.Empty))
            'UserControlLabel1.Parent = Image1
            'UserControlLabel1.Location = position13
            UserControlLabel1.BackColor = Color.Red
    
    
    
            Dim position12 = Image1.PointToClient(UserControl12.PointToScreen(Point.Empty))
            UserControl12.Parent = Image1
            UserControl12.Location = position12
            UserControl12.Text = "888888888888888888888"

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Trying to make the property pages work, made some progress but never recognizes the value in the user control

    I can create a description
    I can change the value, like put in 5

    The value though here is always 10

    In my thinking, it would return 5?

    ASFAIK, no value of 10 is set anywhere in the code, so how can it say it has 10?

    Code:
    ?Anumber
    
    10
    ?_rad
    10
    the code I am trying

    Code:
        ''' <summary>
        ''' Returns "ANumber"
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private _rad As Integer
        Public Property ANumber() As Integer
            Get
                Return _rad
            End Get
            Set(ByVal value As Integer)
                _rad = value
            End Set
        End Property
    properties screenshot of ANumber with 5, it takes whatever number you want

    What do I need to do here? I am stuck at the moment.
    Attached Images Attached Images  
    Last edited by sdowney1; Jun 23rd, 2024 at 09:51 AM.

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Made more progress, finally got a 5 out of it!

    Code:
    ?_rad
    5
    ?anumber
    0
    by this here

    Code:
      Public Property ANumber() As Integer
          Get
              'This will assign the initial value
              '    ANumber = 5
          End Get
    
          Set(ByVal value As Integer)
              ' Assign the value when it is changed in the properties window
              _rad = value
          End Set
    
    End Property
    I spent 2 hours looking at all sorts of crappy code examples and fruitless discussions between other people, then I found this site with a clear explanation of how to do it. Seems to have worked.


    https://www.dotnetspider.com/resourc...ing-VBNET.aspx

    And this too. actually not sure about this, but it seems to need it.
    without this , I cant enter any number after the description.


    Code:
    ''' <summary>
     ''' Returns "ANumber"
     ''' </summary>
     ''' <value></value>
     ''' <returns></returns>
     ''' <remarks></remarks>
    https://stackoverflow.com/questions/...erty-in-vb-net

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    I just rolled back vs2022 to earlier version due to too many crashes.

    I can't set the property page for 'ANumber' in the designer, it shows a 5, only takes a 5, as type in 20, it reverts to 5.
    Something changed. My code did not. It used to let me, so obviously it's being flakey.

    I can though do it programmatically like this to set the radius.

    How do you enable a designer property to accept a value typed into a property page for a control?

    Code:
            UserControl12.ANumber = 20
            UserControlLabel1.ANumber = 20
    The code at the moment for the property is this

    Code:
        ''' <summary>
        ''' Returns "ANumber"
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ''' 
        Public _radius As Integer
        Public Property ANumber() As Integer
            Get
                'This will assign the initial value
                ANumber = 5
            End Get
    
            Set(ByVal value As Integer)
                ' Assign the value when it is changed in the properties window
                _radius = value
            End Set
        End Property

  30. #30
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Code:
    ''' <summary>
    ''' Returns _radius
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' 
    Private _radius As Integer = 5  'This will assign the initial value
    Public Property ANumber() As Integer
        Get      
            Return _radius
        End Get
        Set(ByVal value As Integer)
            ' Assign the value when it is changed in the properties window, OR in code
            _radius = value
        End Set
    End Property
    Last edited by .paul.; Jun 23rd, 2024 at 12:35 PM.

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Quote Originally Posted by .paul. View Post
    Code:
    ''' <summary>
    ''' Returns _radius
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' 
    Private _radius As Integer = 5  'This will assign the initial value
    Public Property ANumber() As Integer
        Get      
            Return _radius
        End Get
        Set(ByVal value As Integer)
            ' Assign the value when it is changed in the properties window, OR in code
            _radius = value
        End Set
    End Property

    Thanks.

    Ok, I just tried this too, and it is working, leaving out the other stuff.
    Seems the rollback of vs2022 has been stable.
    It was acting very flakey, not working like it should and doing odd things.


    'https://stackoverflow.com/questions/5096926/what-is-the-get-set-syntax-in-c
    Code:
        Private _radius As Integer
    
        Public Property ANumber() As Integer
            Get
                Return _radius
            End Get
    
            Set(value As Integer)
                'Assign the value when it is changed in the properties window
                _radius = value
            End Set
        End Property

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    yes, working, a lot of things happening today!

    Now will give a try at coding in a pen property color.
    I plan to change the property names to something better, this is just testing.
    EDITING found it here

    I also found, after adding a Public Property, if I shut down and restart vs2022, the public property appears in the property page

    https://www.w3computing.com/vb2008/v...ustom-control/

    This returns a color, works!

    Code:
        Dim _PenColor As Color
        Public Property AMandatoryColor() As Color
            Get
                Return _PenColor
            End Get
            Set(ByVal value As Color)
                _PenColor = value
            End Set
        End Property

    Code:
    ?_PenColor
    "{Name=Cyan, ARGB=(255, 0, 255, 255)}"
        A: 255
        B: 255
        G: 255
        IsEmpty: False
        IsKnownColor: True
        IsNamedColor: True
        IsSystemColor: False
        Name: "Cyan"
        [R]: 0
    Last edited by sdowney1; Jun 23rd, 2024 at 02:17 PM.

  33. #33

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Got it working, the Pen color will only appear on the control when program runs
    but color is selected in the designer property page.

    Using it this way, individual labels can be created with different border colors and radius.
    Another property I will do is the pen thickness.

    It's really fun when you get things working.
    I wonder if that border pen color appear in the designer for the label, right now it is white.
    Be nice to see it change to red when selecting the color property before the program executes.

    Code:
        Private _radius As Integer = 5
        Private _PenColor As Color
        Public Property ANumber() As Integer
            Get
                Return _radius
            End Get
    
            Set(value As Integer)
                'Assign the value when it is changed in the properties window
                _radius = value
            End Set
        End Property
    
    
        Public Property AMandatoryColor() As Color
            Get
                Return _PenColor
            End Get
            Set(ByVal value As Color)
                _PenColor = value
            End Set
        End Property

    Code:
        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            '  https://learn.microsoft.com/en-us/dotnet/api/system.drawing.region.-ctor?view=net-8.0
    
            Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
            'Debug.Print("Hello")
    
            Using bb As GraphicsPath = GetPath(rect, _radius)
                Dim Region As New Region(bb)
                Me.Region = Region
                'Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                'e.Graphics.FillPath(br, bb)
                'End Using
    
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 0, 0), 4), bb) 'red
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 255, 255, 255), 5), bb) 'white
                'e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 0, 0, 0), 10), bb) 'black
    
                e.Graphics.DrawPath(New Pen(_PenColor, 10), bb) 'white
            End Using
        End Sub
    Attached Images Attached Images  

  34. #34
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    After the property setter line, put Me.Refresh. It should work at Design time

  35. #35

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Quess what, it is working in the designer window. Make a change in property pages, go back click the form, and everything updates on the usercontrol.
    I now have penwidth, pencolor, radius working in the prop pages.

    Code:
        Public Property APenWidth() As Integer
            Get
                Return _PenWidth
            End Get
            Set(ByVal value As Integer)
                _PenWidth = value
            End Set
        End Property
    And then for the draw Pen

    Code:
    e.Graphics.DrawPath(New Pen(_PenColor, _PenWidth), bb) 'user property

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Quote Originally Posted by .paul. View Post
    After the property setter line, put Me.Refresh. It should work at Design time
    will try it
    I did find if you click back on the form, it updates the usercontrol perfectly.

    Wonder if any other properties I might want to code for?

  37. #37
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Clicking back on the design time form causes a repaint, as does Me.Refresh

  38. #38
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,583

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    After the property setter line, put Me.Refresh. It should work at Design time

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    Reading on a forum, the ... lines are something for intellisense use in vs2022?

    And if you want a description of the property in the property page, do this.

    <Description("The radius for the corners.")>

    Editing to fix XML intellisense summary comment from web site below.

    https://stackoverflow.com/questions/...erty-in-vb-net

    Code:
        ''' <summary>
        ''' Returns "The radius for the corners."
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Description("The radius for the corners.")>
        Public Property ANumber() As Integer
            Get
                Return _radius
            End Get
    
            Set(value As Integer)
                'Assign the value when it is changed in the properties window
                _radius = value
            End Set
        End Property
        ''' <summary>
        ''' Returns "The color of the pen rim to draw."
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Description("The color of the pen rim to draw.")>
        Public Property AMandatoryColor() As Color
            Get
                Return _PenColor
            End Get
            Set(ByVal value As Color)
                _PenColor = value
            End Set
        End Property
        ''' <summary>
        ''' Returns "The width of the pen to draw."
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Description("The width of the pen to draw.")>
        Public Property APenWidth() As Integer
            Get
                Return _PenWidth
            End Get
            Set(ByVal value As Integer)
                _PenWidth = value
            End Set
        End Property
    Last edited by sdowney1; Jun 23rd, 2024 at 05:06 PM.

  40. #40

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    873

    Re: [RESOLVED] rounded corner label test look terrible, can we get rid of the rectang

    I changed the names of the 3 properties to Lsomething to keep all 3 lined up in order, that way they are not spread apart in the property window.

    And vs2022 is slow to update the designer.vb file, but it does do it.

    Here are the designer entries for those 2 usercontrols showing the Lsomething properties
    Code:
      'UserControlLabel1
      '
      Me.UserControlLabel1.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(128, Byte), Integer))
      Me.UserControlLabel1.Location = New System.Drawing.Point(445, 441)
      Me.UserControlLabel1.LPenColor = System.Drawing.Color.Lime
      Me.UserControlLabel1.LPenWidth = 5
      Me.UserControlLabel1.LRadiusCorner = 50
      Me.UserControlLabel1.Name = "UserControlLabel1"
      Me.UserControlLabel1.Size = New System.Drawing.Size(228, 62)
      Me.UserControlLabel1.TabIndex = 23
      Me.UserControlLabel1.Text = "UserControlLabel1"
      '
      'UserControl12
      '
      Me.UserControl12.BackColor = System.Drawing.Color.Transparent
      Me.UserControl12.Font = New System.Drawing.Font("Arial", 16.2!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.UserControl12.ForeColor = System.Drawing.Color.Black
      Me.UserControl12.Location = New System.Drawing.Point(284, 365)
      Me.UserControl12.LPenColor = System.Drawing.Color.Red
      Me.UserControl12.LPenWidth = 20
      Me.UserControl12.LRadiusCorner = 10
      Me.UserControl12.Name = "UserControl12"
      Me.UserControl12.Size = New System.Drawing.Size(340, 63)
      Me.UserControl12.TabIndex = 21
      Me.UserControl12.Text = "Crazy Stuff"
      Me.UserControl12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width