Results 1 to 2 of 2

Thread: [2008] adding/removing user controls

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    [2008] adding/removing user controls

    Hokay, here's what I am trying to do:

    I created a simple user control with a label and a textbox. No public properties yet, no methods, no functions.

    In my main form, there is a method called "UploadFile". This method executes when the user uploads a file. This method is part of a threadpool, so two methods might occur simultanously. My goal is everytime this method is run, it creates an instance of the usercontrol (will probabaly put a progress bar in there and everything), and add it on the main form.
    I HAVE NO PROBLEM ADDING IT TO THE FORM.

    Here is my method:

    In the starting of my method I have the following:

    vb.net Code:
    1. Private Sub addProgress()
    2.         Dim _found As Boolean = False
    3.         Dim pre As uploadprogress = Nothing
    4.         Dim preLocation As Integer
    5.         Dim ctl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.        
    6.         Do Until ctl Is Nothing
    7.             'Use ctl here.          
    8.             If TypeOf (ctl) Is uploadprogress Then
    9.                 preLocation = ctl.Location.Y
    10.                 _found = True
    11.                 pre = ctl
    12.             End If
    13.             ctl = Me.GetNextControl(ctl, True) 'Get the next control in the tab order.      
    14.         Loop
    15.  
    16.         If _found And pre IsNot Nothing Then
    17.             u_view = New uploadprogress
    18.             Me.Controls.Add(u_view)
    19.             u_view.BringToFront()
    20.             u_view.Location = New Point(6, preLocation + pre.Height)
    21.         Else
    22.             u_view = New uploadprogress
    23.             Me.Controls.Add(u_view)
    24.             u_view.BringToFront()
    25.             u_view.Location = New Point(6, 119 + 91)
    26.         End If
    27.      
    28.  
    29.     End Sub

    u_view is declared as "private withevents as [usercontrol class name]"

    Okay so this adds the usercontrol fine! However, when my UploadFile Method ENDS, I want to remove the usercontrol. My main form automatically grows when a usercontrol is added to the bottom, so I would like to shrink it when it is removed..

    but my question is.. how do I remove this user control.

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: [2008] adding/removing user controls

    Where is the upload method? is it in the user control or the form. Basically a user control behaves like any other class, IE it can be destroyed after use.

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