473,767 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Controls add/remove and Dispose

Hi,

If I add programatically a Panel to a control, and a Label add to that
Panel. Then when I Dispose the Panel do I have to Dispose the Label
also, or does the Panel take care of that ? And if it is do I gain time
doing it myself or not ?

I ask this because if I for example put panels or labels on Mappoint
ActiveX control, and I don't dispose them myself it take a lot of time
to destroy the activeX control. But maybe this is not the truth with
dotNet controls like a panel or label ?

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz
Jan 31 '07 #1
2 4935
Hi Wilfried,

Here's a tip. First, create a Panel in your form. Add a label to it. Then
look at the designer-generated code. All you have to do then is write the
code which does this by essentially copying the designer-generated code.
Whatever it does when it adds the panel and the label, you do the same.
Whatever it does when disposing the form, you do the same.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

"Wilfried Mestdagh" <wi******@mestd agh.bizwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
Hi,

If I add programatically a Panel to a control, and a Label add to that
Panel. Then when I Dispose the Panel do I have to Dispose the Label also,
or does the Panel take care of that ? And if it is do I gain time doing it
myself or not ?

I ask this because if I for example put panels or labels on Mappoint
ActiveX control, and I don't dispose them myself it take a lot of time to
destroy the activeX control. But maybe this is not the truth with dotNet
controls like a panel or label ?

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz

Jan 31 '07 #2
The simplest rule:
If an object implements IDisposable (has a "Dispose" method), then your code
should call that method. Otherwise, "don't worry, be happy".
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Wilfried Mestdagh" wrote:
Hi,

If I add programatically a Panel to a control, and a Label add to that
Panel. Then when I Dispose the Panel do I have to Dispose the Label
also, or does the Panel take care of that ? And if it is do I gain time
doing it myself or not ?

I ask this because if I for example put panels or labels on Mappoint
ActiveX control, and I don't dispose them myself it take a lot of time
to destroy the activeX control. But maybe this is not the truth with
dotNet controls like a panel or label ?

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz
Feb 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1278
by: et | last post by:
I have the situation where a C# dll is loaded and it provides some controls to display, I wrap the controls in some nice group boxes, and later on I dispose of the group boxes, making sure I remove the controls since I don't want them to be disposed of yet. If I do this a couple of time ie. wrapping controls in my group boxes and setting the references of the group boxes to nothing while keeping a reference to the controls, the controls...
8
1142
by: jcrouse | last post by:
I have a test app with one button and a context menu. When I click on the button, it adds a label with some properties, one being the assignment of the context menu. If I add 5 buttons then want to delete one I can right click and choose Delete from the context menu. The problems is that I don't know the proper verbage to search for (in help) to find the code to tell which label is the one the received the right click event. I'm not sure if...
8
10104
by: Aaron Smith | last post by:
I have a problem... Have a form, made some changes.. now all the controls are gone. I didn't make any changes to the designer generated region.. I'm not really sure what happened to them, but this has happened before where one or two will disappear.. They are still in the code too.. And if I try to add a new control with the same name, it says it exists... Any ideas? -- --- Aaron Smith Remove -1- to E-Mail me. Spam Sucks.
8
3589
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
8
3734
by: hunanwarrior | last post by:
I added textbox controls to a form when user selects amount to create from a combobox as follows: 'Load up the combobox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer For i = 1 To 10 cbxItemCnt.Items.Add(i) Next
1
2035
by: Martin | last post by:
Hi all ! I use Visual Studio .NET 2005 SP1 (+ Updates for Vista) on Windows Vista. I have a strange problem in a WinForm application. In a UserControl, which inherit another UserControl (simply contains a SplitterPanel), I've added controls (most of them are TextBox with the property Anchors set to Left and Right) to Panel2. All theses controls fits in the UserControl and when I resize it, all the controls have the correct behavior....
1
8370
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an instance of an object.'" I've traced the problem to a custom control I created that inherits from Inherits System.Windows.Forms.TextBox. In this custom control, I have two constructors. I'm not sure why I created the second constructor -- it was so...
2
9093
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following code the dynamically adds a specific number of controls. for x as integer = 1 to 10 Dim btn as Windows.Forms.Button = New Windows.Forms.Button btn.Name = "btn" & x btn.Text = "Test" & x controls.add(btn) next x This results in 10 buttons appearing on the screen. I've excluded the
32
2790
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put some new ones on. In my code I am doing the following: For Each ctrl In tpMain.Controls If TypeOf (ctrl) Is CheckBox Then If ctrl.Name.StartsWith("chkS") Then ctrl.Visible = False
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.