Results 1 to 8 of 8

Thread: Custom Control Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4

    Custom Control Question

    I am fairly new to VB.Net. I have created a Custom Control with a couple of buttons on it. I am adding this control to a form programmatically at run time. I want one button on the control to be used to remove the control when it is clicked. I'm sure that there is a simple solution, but I am stumped.

    My routine to add the control to the form works fine

    Code:
     Private DynamicControl As New Object()
       
     Private Sub cmdCreateNew_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles cmdCreateNew.Click
    
          Dim NewControl As New ctrlCustomerInfo()
    
            NewControl.Left = 150
            NewControl.Top = 100
    
            Me.Controls.Add(NewControl)
            AddHandler NewControl.Click, AddressOf NewControl_Click
    
            DynamicControl = NewControl
       End Sub
    I also have a button already on the form that will take the control down. That works fine.

    Code:
    Private Sub cmdClear_Click(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles cmdClear.Click
    
            Dim MyControl As ctrlCustomerInfo
            MyControl = DynamicControl
           Me.Controls.Remove(MyControl)
    
       End Sub
    What I want to do is use a button that is on the new control in order to take the control down, but I can’t figure out how to do that.

    Any help would be greatly appreciated
    Last edited by SmartTrac; Apr 6th, 2004 at 08:57 PM.

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    you can use mycontrol.visible= false or mycontrol.hide

    thats assuming you inherited from windows.forms.controls

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    Thanks Andy,

    That seems to have worked. What will that do to the Control stack (I assume there is one) as far as memory allocation is concerned? I am doing a Control.Add, but it doesn't look like I am removing the control from the stack.

    Once this control is complete, it will be pulling a Customer record in from the database and allowing editing. This may happen many times during the course of the day, so this control will be created and hidden many times. Of course, before I close the control, I will clear everything on the control and then call Me.dispose. Will that be sufficient?
    Last edited by SmartTrac; Apr 6th, 2004 at 11:39 PM.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    yeah. the dispose method will be fine but you can't predict when the garbage collector will get around to cleaning the stack. It's not really a big deal to most but some people create custom dispose methods.

    I'm not really keen on that aspect yet. but, if you're simply going to hide and unhide the control, personally, I think that's better because it will be in memory and the processor won't have to work every time you need that control created. That could drain performance.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    Thanks again,

    This application is going to be fairly complex and I need it to be robust. I am converting an old DOS program that was written in C and used Btrieve as a data handler. It is a program that is used in auto repair shops for shop management.

    Do you know any good, but inexpensive grid packages? I'm currently trying out XtraGrid 2.0, but it seems a bit buggy.

    Charlie

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    grid packages? I sure dont.

    That's a good question though. I've not looked around for 3rd party tools. We have some for vb6 at work. I'll see if we have any new ones in and if so, I'll see if I can't get you some info on them.


  7. #7
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Here's some info on how to force Garbage Collection from msdn:


    Forcing a Garbage Collection

    The garbage collection GC class provides the GC.Collect method, which you can use to give your application some direct control over the garbage collector. In general, you should avoid calling any of the collect methods and allow the garbage collector to run independently. In most cases, the garbage collector is better at determining the best time to perform a collection. In certain rare situations, however, forcing a collection might improve your application's performance. It might be appropriate to use the GC.Collect method in a situation where there is a significant reduction in the amount of memory being used at a defined point in your application's code. For example, an application might use a document that references a significant number of unmanaged resources. When your application closes the document, you know definitively that the resources the document has been using are no longer needed. For performance reasons, it makes sense to release them all at once. For more information, see the GC.Collect Method.

    Before the garbage collector performs a collection, it suspends all currently executing threads. This can become a performance issue if you call GC.Collect more often than is necessary. You should also be careful not to place code that calls GC.Collect at a point in your program where users could call it frequently. This would defeat the optimizing engine in the garbage collector, which determines the best time to run a garbage collection.

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    4
    Thanks again Andy,

    You have been a big help

    Charles

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