|
-
Aug 19th, 2008, 06:43 AM
#1
Thread Starter
Frenzied Member
[2005] Working out Which controls are in which containers.
Hi,
I know this is a CF question but it applies really to VS2005 design enviroment. I have panels in panels on top of panel etc. Is there anyway I can determine easily which controls are in which panels and which panels and in which main panels?
Cheers,
Jiggy!
PS. I think I have confused my self on screen and don't know wether I have put the panels in the corrrect order.
-
Aug 19th, 2008, 06:52 AM
#2
Re: [2005] Working out Which controls are in which containers.
I have hierarchy like this: Panel 1 -- Panel 2 -- Button1
vb.net Code:
Public Class Form1 Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button1.Click Dim parent1 As Panel Dim parent2 As Panel parent1 = Button1.Parent MessageBox.Show(parent1.Name) ' Will get u Panel 2 parent2 = parent1.Parent MessageBox.Show(parent2.Name) ' Will get u Panel 1 End Sub End Class
-
Aug 19th, 2008, 07:17 AM
#3
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Thanks for that but I wanted to do it in vs2005 design. I have a textbox control somewhere in one of the panels and I cannot find it and need to either delete it or move it to the correct panel.
Cheers,
Jiggy!
-
Aug 19th, 2008, 07:21 AM
#4
Re: [2005] Working out Which controls are in which containers.
oh...ok.. i misunderstood it. If you know the name of that control then select it from the drop down list of properties window. Once you select it from the list, that control will appear as selected in design view. You can then move it to somewhere else.
-
Aug 19th, 2008, 07:27 AM
#5
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Thats the problem, it does not show up in the design window.
-
Aug 19th, 2008, 08:37 AM
#6
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
I think it is in one of my panels behind something so can anyone please give me an example of how to step through each panel on my form and for each panel show all controls in the panel then I can trap for the control name txtNCNotes and see which panel it is in.
Thanks for any help,
Jiggy!
-
Aug 19th, 2008, 09:01 AM
#7
Re: [2005] Working out Which controls are in which containers.
I'm not sure if it's available in a Mobile project but I'd guess that it is. Use the Document Outline window (Ctrl+Alt+T).
-
Aug 19th, 2008, 09:06 AM
#8
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Thank you mate, that is exactly what I want but it does not show the control I am looking for. Any ideas?
-
Aug 19th, 2008, 09:10 AM
#9
Re: [2005] Working out Which controls are in which containers.
Every control is displayed in the Document Outline. If the one you want is not there then it doesn't exist. Perhaps your form has become corrupted. Have you tried opening the designer code file and examining the properties and parent of this control directly?
-
Aug 19th, 2008, 09:12 AM
#10
Re: [2005] Working out Which controls are in which containers.
I'm looking for an answer to that, too. Unfortunately, I am dealing with template generated code, which can be painfully annoying. The controls are created, but they don't show up in the Document Outline view, so they are probably retained as children to a parent control that no longer exists. This happened for me because I changed the name of the parent control, then re-generated the code. I can see where the controls are created, and their properties are set, but nobody owns them. The same situation seems to be true for your textbox, though without a template monkeying with your code, that shouldn't normally happen.
My usual boring signature: Nothing
 
-
Aug 19th, 2008, 09:27 AM
#11
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
This is wierd because I have done the following code in the form load and it does not find the control:-
Code:
Dim ctrlControls As Control
For Each ctrlControls In Me.Controls
If ctrlControls.Name.ToString = "txtNCNotes" Then
MessageBox.Show(panDepartments.Name.ToString)
End If
Next
Any ideas or can someone tell me how I delete the control from my form without being able to select it.
Cheers,
Jiggy!
-
Aug 19th, 2008, 09:30 AM
#12
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
It is in the .VB file as follows:-
Code:
'txtNCNotes
'
Me.txtNCNotes.Location = New System.Drawing.Point(64, 29)
Me.txtNCNotes.Multiline = True
Me.txtNCNotes.Name = "txtNCNotes"
Me.txtNCNotes.Size = New System.Drawing.Size(161, 48)
Me.txtNCNotes.TabIndex = 5
Me.txtNCNotes.TabStop = False
-
Aug 19th, 2008, 09:31 AM
#13
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Can I just remove all instances of it from the .VB file to delete it and then start again?
-
Aug 19th, 2008, 10:22 AM
#14
Re: [2005] Working out Which controls are in which containers.
Yeah, that should work, since I end up doing it all the time with this template derived code. VS doesn't like you tinkering with that section, and sometimes it complains, but just deleting a control should raise no issues.
My usual boring signature: Nothing
 
-
Aug 19th, 2008, 10:28 AM
#15
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Yeh I deleted it and renamed an existing textbox2 to txtNCNotes and it took hold of all the events and seems to work fine.
Cheers All for your help,
Jiggy!
-
Aug 19th, 2008, 10:33 AM
#16
Re: [2005] Working out Which controls are in which containers.
I'd like a better solution than that one, if anybody has one. In my case, I have lost the container for many controls (about a dozen). Deleting them and re-creating the whole lot is an option, but only a disturbingly temporary one.
Therefore, if anybody knows how to find controls that are created, but are not displayed, and are child controls of non-existant parents (orphan controls, I suppose), I'd like to hear a solution.
My usual boring signature: Nothing
 
-
Aug 19th, 2008, 11:03 AM
#17
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
There must be a location where the relationship is setup and maybe those controls are still pointing to the deleted container. I will do some search myself. Would be good for the future to get a correct solution.
-
Aug 19th, 2008, 12:50 PM
#18
Re: [2005] Working out Which controls are in which containers.
I solved the problem, and here's the solution:
If you look in the document outline (CTL+ALT+T), and the control is not there, then it either doesn't exist, or it was not added to the controls collection of the proper container control. If the control exists in the Property Manager list, then the first option is ruled out. Therefore, to fix the problem, all you need to do is go into the InitializeComponents sub and add in the line Me.<ContainerControl>.Controls.Add(<MissingControl>). This line gets added into the section where all the properties for the container controls are set, which is towards the bottom of the InitializeComponents Sub. You will see plenty of other examples nearby for most forms. Once the line has been added (using the right container for ContainerControl), then the control will appear correctly.
Yes, this means editing the section of code that VS tells you NOT to edit, but I'm getting used to that by now.
I'm such a rebel!
My usual boring signature: Nothing
 
-
Aug 19th, 2008, 03:01 PM
#19
Thread Starter
Frenzied Member
Re: [2005] Working out Which controls are in which containers.
Cheers for the reply mate; that makes sense I think!
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
|