Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working with Visual Studio 2017 and I have create a UserControl which requires a borderless form. Is there any way to popup a message if user try to place this control into a non-borderless form? Something like the message box which appears in design view when we give a wrong value at "Properties Window" of any control.

What I have tried:

I noticed that if I add a simple MsgBox into my UserControl's Public Sub New and then place this UserControl into a Form, message box will appears right away after placement.
VB
Public Sub New()
    InitializeComponent()
    MsgBox("Test Message")
End Sub

But, how can I also check if ParentForm is borderless or not? Something like this example below, which of course doesn't work inside Public Sub New because there is no ParentForm yet!!!
VB
Public Sub New()
    InitializeComponent()
    if Not MyBase.ParentForm.FormBorderStyle = FormBorderStyle.None Then
        MsgBox("Test Message")
    End If
End Sub
Posted
Updated 25-Mar-18 23:34pm
v5

1 solution

Αfter some tests I managed to solved it. Into UserControl's Load event (where ParentForm is acceptable), I check first if UserControl is in DesignMode (else user will gets messages everytime application starts) and then, if ParentForm is not FormBorderStyle.None, user informed by a MessageBox.
VB
Private Sub UserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If Not Site Is Nothing AndAlso Site.DesignMode Then
        If Not ParentForm.FormBorderStyle = FormBorderStyle.None Then
            MsgBox("Blah blah blah...")
        End If
    End If
End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900