0
votes

First of all I am working with Visual Studio 2017. I have create a UserControl which requires a borderless form. Is there any way to popup a message if programmer 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.

EDIT

I noticed that if I add a simple MsgBox into my UserControl's Public Sub New and then add this UserControl to a Form, message box appears.

Public Sub New()
    InitializeComponent()
    MsgBox("Test Message")
End Sub

But, how can I check if parent form is borderless or not? Something like this example below, which of course doesn't work inside Public Sub New because there is no parent yet!!!

Public Sub New()
    InitializeComponent()
    if Not MyBase.ParentForm.FormBorderStyle = FormBorderStyle.None Then
        MsgBox("Test Message")
    End If
End Sub
1
Try overriding the OnParentChanged method, which raises the ParentChanged event whenever the control is added to another control. - jmcilhinney
I should also add that OnParentChanged will execute when a control is removed from another control, so be sure to check that Parent isn't Nothing first. - jmcilhinney
Can I have an example please? - Simonetos The Greek
What do you not understand about the examples you found when you searched the web? If I post a comment it's to provide keywords for you to search for yourself. Otherwise I'd have posted an answer. If someone provides you with information, make an attempt to use it first, then ask for more information if and when you need it. Don't just wait for it all to be handed to you. - jmcilhinney
My friend Jim, if you take a look at my questions you will see that I never wait to be handed to me anything. I am asking for an example only because I can't understand how to use your informations, even after I looked for it on the web. I am not any VB.NET specialist and I am still trying to learn things. If the best you can do is to give some keywords, it's acceptable, really thank you for your time, but I don't believe you have the right to offend any person which you don't really know. - Simonetos The Greek

1 Answers

0
votes

Well after 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.

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
            MessageBox.Show("This control works better with a borderless form!!!", "Control Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End If
End Sub