4 Replies - 2312 Views - Last Post: 26 December 2010 - 09:42 PM Rate Topic: -----

#1 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Custom Panel Control

Posted 24 December 2010 - 02:32 AM

Hi, I am currently trying to create a custom panel control which will hold other panels.

I need the panel to detect the other panels that are contained within it when it starts up (these panels will have been dragged onto the container (my control) panel during design time.

Here is what I have tried (alas, it doesn't work)
/// <summary>
/// Dictionary to hold the current panels in the container panel
/// if true, then the panel is expanded
/// </summary>
private Dictionary<Panel, bool> currentPanels = new Dictionary<Panel, bool>();

/// <summary>
/// Default Constructor (entry point)
/// </summary>
public NewPanel()
{
	// get a list of the panels within this container
	foreach (Control c in this.Controls)
	{
		// check to see if it actually is a Panel
		if (c is Panel)
		{
			// add
			currentPanels.Add((Panel)c, false);
		}
	}
}



Is this because this would run before the controls within the panel are created?

Is This A Good Question/Topic? 0
  • +

Replies To: Custom Panel Control

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6536
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Custom Panel Control

Posted 24 December 2010 - 07:15 AM

Basically.
When NewPanel is created the other panels haven't been added to it yet.
Put a breakpoint at line 12.
Run it in debug F5
Over over this.Controls and you should find that collection is empty.

This might help

Bulding an application - Part 1

along with

Debugging tutorial
Was This Post Helpful? 0
  • +
  • -

#3 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Custom Panel Control

Posted 24 December 2010 - 11:59 AM

Yeah, I did establish that myself by debugging and stepping through the code...

I was just wondering if there was a way to do this, or do I need to write another method such as detectPanels() and call that on the form_load event?
Was This Post Helpful? 0
  • +
  • -

#4 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Custom Panel Control

Posted 26 December 2010 - 06:13 PM

anyone got any ideas on this? ( hate to bump :( )
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Custom Panel Control

Posted 26 December 2010 - 09:42 PM

Well, if this panel is extending UserControl (as in, if it's a UI control) then it will have an onload method that you can override.

If not, I suggest making your List into an ObservableCollection and handling the Collectionchanged event.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1