Author Topic: Add special effects to borders  (Read 2105 times)

dzydrmr

  • Newbie
  • *
  • Posts: 5
    • View Profile
Add special effects to borders
« on: November 13, 2014, 09:50:11 AM »
Greetings,
Trying to snaz up different areas of form. Would like to have sunken/raised border to differentiate a system status area of form.
I can't find any way to add a special effect to a border in visual studio 2013 similar to what I can do in MS Access form control/borders.
Any ideas?
Thanks, Edward

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Add special effects to borders
« Reply #1 on: November 13, 2014, 10:02:44 AM »
Try adding a Panel to your form, then set the BorderStyle to Fixed3D. You can then add your controls to the panel.

If this doesn't work, it's not too hard to create a custom panel that will give you any border you want. Here is a very simple demo of creating a custom panel.
- Right click the project AdvancedHMI and select Add New Class
- Put the code shown below in
- Build the project and you should have a PanelWithBorder now in the toolbox.
Code: [Select]
Public Class PanelWithBorder
    Inherits Panel

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)

        '* Draw a top border
        e.Graphics.FillRectangle(Brushes.DarkGray, 0, 0, Me.Width, 10)

        '* Draw a bottom border
        e.Graphics.FillRectangle(Brushes.DarkGray, 0, Me.Height - 10, Me.Width, 10)
    End Sub
End Class

dzydrmr

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Add special effects to borders
« Reply #2 on: November 13, 2014, 11:23:44 AM »
Thank you for the quick reply Archie!

Have been using Panel with BorderStyle set to Fixed3D. Was hoping to have something stand out a little more distinctly. Your code does that, but not quite what I was hoping. Being inexperienced here, I can't quite get something like this to work:

Public Class SunkenBorder
    Public Const SunkenBorder As System.Windows.Forms.Border3DStyle = 10
End Class

Suggestions?

Thanks Again!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Add special effects to borders
« Reply #3 on: November 13, 2014, 12:07:55 PM »
You will need to continue with the GDI+ graphics as shown in my sample, so a complete sunken border may look like this:

Code: [Select]
Public Class PanelWithBorder
    Inherits Panel

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)

        Dim BorderWidth As Integer = 5

        '* Draw a top border
        Dim PolygonPoints(3) As System.Drawing.Point
        PolygonPoints(0) = New Point(0, 0)
        PolygonPoints(1) = New Point(Me.Width, 0)
        PolygonPoints(2) = New Point(Me.Width - BorderWidth, BorderWidth)
        PolygonPoints(3) = New Point(BorderWidth, BorderWidth)
        e.Graphics.FillPolygon(Brushes.DarkGray, PolygonPoints)

        '* Draw a left border
        PolygonPoints(0) = New Point(0, 0)
        PolygonPoints(1) = New Point(0, Me.Height)
        PolygonPoints(2) = New Point(BorderWidth, Me.Height - BorderWidth)
        PolygonPoints(3) = New Point(BorderWidth, BorderWidth)
        e.Graphics.FillPolygon(Brushes.DarkGray, PolygonPoints)

        '* Draw a bottom border
        PolygonPoints(0) = New Point(0, Me.Height)
        PolygonPoints(1) = New Point(Me.Width, Me.Height)
        PolygonPoints(2) = New Point(Me.Width - BorderWidth, Me.Height - BorderWidth)
        PolygonPoints(3) = New Point(BorderWidth, Me.Height - BorderWidth)
        e.Graphics.FillPolygon(Brushes.LightGray, PolygonPoints)

        '* Draw a right border
        PolygonPoints(0) = New Point(Me.Width, 0)
        PolygonPoints(1) = New Point(Me.Width, Me.Height)
        PolygonPoints(2) = New Point(Me.Width - BorderWidth, Me.Height - BorderWidth)
        PolygonPoints(3) = New Point(Me.Width - BorderWidth, BorderWidth)
        e.Graphics.FillPolygon(Brushes.LightGray, PolygonPoints)
    End Sub

End Class

dzydrmr

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Add special effects to borders
« Reply #4 on: November 14, 2014, 12:43:54 AM »
Thanks Archie!
Tweeked your code slightly to get the effect I was looking for and it looks great!

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Add special effects to borders
« Reply #5 on: November 28, 2014, 01:20:44 PM »
Archie,

Regarding borders, if the digital indicator control could be made to not indicate or update, so that any other numerical indicator could be placed inside it, would make an easy way to add the same border as digital indicator for any numerical or text display and maintain consistency for a screen. 

Alternatively, an AHMI panel control with adjustable bezel width would do the trick (similar to that other very expensive HMI that is a "wonder". :)