Results 1 to 12 of 12

Thread: [RESOLVED] Prevent developer from placing a UserControl more than one time in Design Time

Threaded View

  1. #1

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

    Resolved [RESOLVED] Prevent developer from placing a UserControl more than one time in Design Time

    I am working on a UserControl and I am looking for a way to prevent developer to place this UserControl more than one time into a form, in Design Time. In other words, how can I detect if my UserControl is already placed into ParentForm or not, in Design Time and prevent the second placement if there is already one there?

    I tried something like this example below... First I am not sure if this is the "correct" way and second, I can't find how to remove or stop the placement of UserControl in case there is already one.

    Again, all this, in Design Time!!!

    vb.net Code:
    1. Private Sub MyUserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2.     Dim _Count As Integer
    3.     Dim _UserControl As MyUserControl
    4.     For Each _UserControl In Me.ParentForm.Controls
    5.         If _UserControl.Name.Contains("MyUserControl") Then
    6.             _Count += 1
    7.         End If
    8.     Next
    9.     If _Count > 1 Then
    10.         MsgBox("Control have been placed.")
    11.     Else
    12.         MsgBox("Control haven't placed yet.")
    13.     End If
    14. End Sub
    Last edited by Simonetos The Greek; Apr 17th, 2018 at 06:10 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