I have spent hours trying to understand this problem, but I simply can't wrap my head around it.
The issue is when I use the Paint event for 3 groupboxes to draw new borders that stand out more. It works perfectly, but it also draws on one of the sub-controls inside that groupbox. Only the final 2 lines does this and it seems to be related to the controls position within the groupbox.
I can show with a couple of screenshots:
The border itself works perfectly, but it draws lines on the radiobutton controls. If I remove the last two drawn lines on the groupbox (left and bottom), the lines on the radiobuttons will go away..
The drawn line on the radiobutton control here is longer. Not sure why.
If I move the control to the right, the line gets shorter. It would disappear if I moved it further.
I couldn't add the final picture for some reason. so an explanation will have to suffice.
If I move the radiobutton closer to the edge, the line bends. If one squints, the original border can be made out.
Now for the code. I believe that the only thing needed here is the PaintEventHandler that these groupboxes call with their Paint event:
Code: Select all
$groupboxes_Paint=[System.Windows.Forms.PaintEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.PaintEventArgs]
$gfx = $_.Graphics
$string = $this.text
$font = New-Object System.Drawing.Font('Segoe UI', 8.25, [System.Drawing.FontStyle]::Bold)
[int]$stringsize = ($gfx.MeasureString($string, $font)).Width +7
$gfx.SmoothingMode = 'AntiAlias'
$Pen = New-Object System.Drawing.Pen([System.Drawing.Color]::'Black')
$Pen.width = 2
[int]$width = ($_.ClipRectangle.Width - 1)
[int]$height = ($_.ClipRectangle.Height - 2)
$gfx.drawline($Pen, 0, 9, 0, $height)
$gfx.drawline($Pen, 0, 9, 7, 9)
$gfx.drawline($Pen, $stringsize, 9, $width, 9)
$gfx.drawline($Pen, $width, 9, $width, $height)
$gfx.drawline($Pen, $width, $height, 0, $height)
}