|
-
Apr 16th, 2018, 09:40 AM
#1
Re: Prevent developer from placing a UserControl more than one time in Design Time
I don't know of a way to cancel the control creation
Haven't got an ide in front of me to check but you could presumably just remove it:-
Code:
f.Controls.Remove(Me)
By the way, I think there's a typo in your code:-
Should be:-
Code:
Dim c = f.GetNextControl(c, True)
Unless you actually want to check the control isn't the form for some reason
edit> crossed over
You may or may not want this:-
While that's in they could add a second control to the form at run time.
Not quite. The "On" methods fire the events and are the intended method for firing the event from code, rather than calling the handling event directly. The correct way to wire up an event handler is the first one.
Last edited by FunkyDexter; Apr 16th, 2018 at 09:55 AM.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 16th, 2018, 09:58 AM
#2
Thread Starter
Lively Member
Re: Prevent developer from placing a UserControl more than one time in Design Time
 Originally Posted by FunkyDexter
You may or may not want this:- While that's in they could add a second control to the form at run time.
Do you mean if developer try to add this control programmatically?
-
Apr 16th, 2018, 10:17 AM
#3
Thread Starter
Lively Member
Re: Prevent developer from placing a UserControl more than one time in Design Time
 Originally Posted by FunkyDexter
You may or may not want this...
So I ended up on this...
vb.net Code:
Private Sub Me_ParentChanged(sender As Object, e As EventArgs) Handles Me.ParentChanged If Me.ParentForm IsNot Nothing Then Dim _UserControl = DirectCast(Me.ParentForm, Control) If _UserControl IsNot Nothing Then Do Until _UserControl Is Nothing If TypeOf _UserControl Is CmosTitleBar AndAlso _UserControl IsNot Me Then Throw New ArgumentOutOfRangeException("", "You can place only one " & _UserControl.Name & " control per form.") End If _UserControl = _UserControl.GetNextControl(_UserControl, True) Loop End If End If End Sub
Last edited by Simonetos The Greek; Apr 17th, 2018 at 06:00 AM.
-
Apr 16th, 2018, 05:09 PM
#4
Re: Prevent developer from placing a UserControl more than one time in Design Time
 Originally Posted by Simonetos The Greek
So I ended up on this...
Code:
Private Sub Me_ParentChanged(sender As Object, e As EventArgs) Handles Me.ParentChanged
If Me.ParentForm IsNot Nothing Then
Dim _UserControl = DirectCast(Me.ParentForm, Control)
If _UserControl IsNot Nothing Then
Do Until _UserControl Is Nothing
If TypeOf _UserControl Is CmosTitleBar AndAlso _UserControl IsNot Me Then
Throw New ArgumentOutOfRangeException("", "You can place only one " & _UserControl.Name & " control per form.")
End If
_UserControl = _UserControl.GetNextControl(_UserControl, True)
Loop
End If
End If
End Sub
This is incorrect : _UserControl = _UserControl.GetNextControl(_UserControl, True)
... it will only go into controls... look @ my first example...
-
Apr 17th, 2018, 01:41 AM
#5
Thread Starter
Lively Member
Re: Prevent developer from placing a UserControl more than one time in Design Time
 Originally Posted by i00
This is incorrect : _UserControl = _UserControl.GetNextControl(_UserControl, True)
... it will only go into controls... look @ my first example...
Yes but I can't understand this part What is f and what is c? If f is the ParentForm and c the UserControl, then why c=f?
Last edited by Simonetos The Greek; Apr 17th, 2018 at 06:09 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|