|
-
Apr 14th, 2018, 01:54 AM
#1
Thread Starter
Lively Member
[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:
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick Me.ControlBox = Me.ParentForm.ControlBox If ParentForm.ControlBox = True Then ControlsBox_FlowLayoutPanel.Visible = True Else ControlsBox_FlowLayoutPanel.Visible = False If ParentForm.MinimizeBox = True Then MinimizeButton_PictureBox.Visible = True Else MinimizeButton_PictureBox.Visible = False Me.MinimizeBox = Me.ParentForm.MinimizeBox If ParentForm.MaximizeBox = True Then MaximizeButton_PictureBox.Visible = True Else MaximizeButton_PictureBox.Visible = False Me.MaximizeBox = Me.ParentForm.MaximizeBox 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:
Private WithEvents _ParentForm As Form Protected Overrides Sub OnParentChanged(e As EventArgs) MyBase.OnParentChanged(e) _ParentForm = Me.ParentForm Call ParentForm_TextChanged() End Sub Private Sub ParentForm_TextChanged() Handles _ParentForm.TextChanged If _ParentForm Is Nothing Then FormTitle_Label.Text = FormTitle_Label.Text Else FormTitle_Label.Text = _ParentForm.Text End If Invalidate() 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.
-
Apr 18th, 2018, 05:59 AM
#2
Thread Starter
Lively Member
Re: How can I detect when ParentForm's properties are changing?
Last edited by Simonetos The Greek; Apr 18th, 2018 at 08:20 AM.
-
Apr 18th, 2018, 08:38 PM
#3
Re: How can I detect when ParentForm's properties are changing?
Not reliably ... the problem is that there is no changed event for the stuff you listed...
The property grid uses the PropertyDescriptors to change properties ... so I though I could hook into those in design time...
However in design the ValueChanged is not triggered???
Kris
-
Apr 19th, 2018, 04:45 AM
#4
Thread Starter
Lively Member
Re: How can I detect when ParentForm's properties are changing?
Well, here is an example on how we can detect when ParentForm's properties are changing and then do our stuff...
vb.net Code:
Private WithEvents _ParentForm As Form Protected Overrides Sub OnParentChanged(e As EventArgs) MyBase.OnParentChanged(e) _ParentForm = Me.ParentForm Call ParentForm_TextChanged() Call ParentForm_StyleChanged() End Sub Private Sub ParentForm_TextChanged() Handles _ParentForm.TextChanged If _ParentForm IsNot Nothing Then FormTitle_Label.Text = _ParentForm.Text Invalidate() End Sub Private Sub ParentForm_StyleChanged() Handles _ParentForm.StyleChanged If _ParentForm IsNot Nothing Then If _ParentForm.ControlBox = True Then ControlsBox_FlowLayoutPanel.Visible = True Else ControlsBox_FlowLayoutPanel.Visible = False If _ParentForm.MinimizeBox = True Then MinimizeButton_PictureBox.Visible = True Else MinimizeButton_PictureBox.Visible = False If _ParentForm.MaximizeBox = True Then MaximizeButton_PictureBox.Visible = True Else MaximizeButton_PictureBox.Visible = False End If End Sub
-
Apr 23rd, 2018, 12:07 PM
#5
Re: How can I detect when ParentForm's properties are changing?
It seems to me that the above code doesn't do what you claim it does. The user could change the Form's properties such as Text or ControlBox over and over again, but the custom title bar won't change until its OnParentChanged sub is called. And when do you do that? The only way to trigger OnParentChanged in the Designer is to delete the existing custom title bar (if any) and add a new one.
I think it would be better to do it the reverse way. In other words, define (or override) Text, ControlBox etc. as properties of the custom title bar. You could then use the Set clauses of these properties to change the corresponding parent form properties.
BB
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|