Я немного упростил код и подключил большинство событий к одному методу.Больше нет Формы-A, только Форма-B.Form-B теперь создает свою собственную Form-A на лету без необходимости создавать файл кода.Я переместил размер границы в переменную, чтобы его было легко настроить.
Imports System.Runtime.InteropServices
Public Class InnerForm
Private borderSize As Integer = 10
Private border As Form = New Form()
Private Sub InnerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
border.FormBorderStyle = Windows.Forms.FormBorderStyle.None
border.ShowInTaskbar = False
border.BackColor = Color.Blue
border.Opacity = 0.5
border.Enabled = False
RefreshBorder()
End Sub
Private Sub DrawRectangle()
Dim p As New Drawing2D.GraphicsPath()
p.StartFigure()
p.AddArc(New Rectangle(0, 0, 40, 40), 180, 90)
p.AddLine(40, 0, border.Width - 40, 0)
p.AddArc(New Rectangle(border.Width - 40, 0, 40, 40), -90, 90)
p.AddLine(border.Width, 40, border.Width, border.Height - 40)
p.AddArc(New Rectangle(border.Width - 40, border.Height - 40, 40, 40), 0, 90)
p.AddLine(border.Width - 40, border.Height, 40, border.Height)
p.AddArc(New Rectangle(0, border.Height - 40, 40, 40), 90, 90)
p.CloseFigure()
border.Region = New Region(p)
End Sub
Private Sub RefreshBorder()
border.Show()
border.Size = New Size(Me.Width + borderSize * 2, Me.Height + borderSize * 2)
border.Location = New Point(Me.Location.X - borderSize, Me.Location.Y - borderSize)
DrawRectangle()
SetWindowPos(border.Handle, Me.Handle, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE)
Me.BringToFront()
End Sub
Private Sub frmMAin_Refresh(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.GotFocus, Me.Move, Me.Activated, Me.SizeChanged, MyBase.Shown
'dont show when maximized or minimized, else show it'
If Me.WindowState = FormWindowState.Maximized Or Me.WindowState = FormWindowState.Minimized Then
border.Hide()
Else
RefreshBorder()
End If
End Sub
<DllImport("user32.dll")> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
End Function
Public Const SWP_NOSIZE As Int32 = &H1
Public Const SWP_NOMOVE As Int32 = &H2
Public Const SWP_NOACTIVATE As Int32 = &H10
End Class
Дайте мне знать, если это работает для вас.