Results 1 to 5 of 5

Thread: [RESOLVED] How can I detect when ParentForm's properties are changing?

Threaded View

  1. #1

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Resolved [RESOLVED] How can I detect when ParentForm's properties are changing?

    Greetings to everyone!!!


    I am working on a couple of UserControls lately and this time is a custom TitleBar. What I want to do is to detect when ParentForm's properties (like ControlBox for example) is changing by developer in Design Time and then update my TitleBar.

    So I added a Timer into my UserControl to do this "work". It works, but I think this isn't the most appropriate approach...
    vb.net Code:
    1. Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick     Me.ControlBox = Me.ParentForm.ControlBox
    2.     If ParentForm.ControlBox = True Then ControlsBox_FlowLayoutPanel.Visible = True Else ControlsBox_FlowLayoutPanel.Visible = False
    3.     If ParentForm.MinimizeBox = True Then MinimizeButton_PictureBox.Visible = True Else MinimizeButton_PictureBox.Visible = False
    4.     Me.MinimizeBox = Me.ParentForm.MinimizeBox
    5.     If ParentForm.MaximizeBox = True Then MaximizeButton_PictureBox.Visible = True Else MaximizeButton_PictureBox.Visible = False
    6.     Me.MaximizeBox = Me.ParentForm.MaximizeBox
    7. End Sub
    Is there any other way to do that and not by using a Timer? For example, to detect ParentForm's Text property and then update my UserControl's Text, I do something like this...
    vb.net Code:
    1. Private WithEvents _ParentForm As Form
    2.  
    3. Protected Overrides Sub OnParentChanged(e As EventArgs)
    4.     MyBase.OnParentChanged(e)
    5.     _ParentForm = Me.ParentForm
    6.     Call ParentForm_TextChanged()
    7. End Sub
    8.  
    9. Private Sub ParentForm_TextChanged() Handles _ParentForm.TextChanged
    10.     If _ParentForm Is Nothing Then
    11.         FormTitle_Label.Text = FormTitle_Label.Text
    12.     Else
    13.         FormTitle_Label.Text = _ParentForm.Text
    14.     End If
    15.     Invalidate()
    16. End Sub
    Is there anything similar for properties like ControlBox, MinimizeBox and MaximizeBox?

    Thank you in advance!!!
    Last edited by Simonetos The Greek; Apr 18th, 2018 at 08:19 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width