472,983 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Clarifying creation/destruction of TreeVew.Handle and collapse behaviour

Hi,

I have a WinForms application (C#, VS 2005) that consists of a treeview control and a notify icon. Below is a complete example of this application. The treeview has one root node and one child node. When I close the form, it will not be closed but minimised to the system tray. A double-click on the notify icon wakes it up and displays it again.

My expection was that the treeview handle would be destroyed when the form is sent to the system tray and re-created when shown again. Also, I expected my treeview to display my nodes the way they were before I minimized the form. Here is what I actually observed:

1. When the form is sent to the system tray the treeview handle will be destroyed and re-created.
2. When the form is shown again the treeview handle will also be destroyed and re-created.
3. When all tree nodes are expanded and the focus is on the root node, minimising and showing the form leads to a collapsed treeview.
4. When all tree nodes are expanded and the focus is on the child node, minimising and showing the form does not collapse the treeview. I assume that showing the treeview again results in a collapse of only the focused node. Is that correct?

Are there any reasons why the handle will be destroyed and re-created so frequently?
Also, why is there a built in logic to collapse tree nodes at all? It should be mentioned that the BeforeCollapse or AfterCollapse events will not be raised.

This scenario does not produce any errors but I find it annoying that my treeview does not come back from the system tray the way it was before and I would like to understand why this is not the case.

Thanks a lot,

Marc.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
this.notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);
this.treeView1.HandleDestroyed += new EventHandler(treeView1_HandleDestroyed);
this.treeView1.HandleCreated += new EventHandler(treeView1_HandleCreated);
this.treeView1.BeforeCollapse += new TreeViewCancelEventHandler(treeView1_BeforeCollaps e);
this.treeView1.AfterCollapse += new TreeViewEventHandler(treeView1_AfterCollapse);

this.treeView1.Nodes.Add(new TreeNode("Parent", new TreeNode[] { new TreeNode("Child") }));
}

void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}

void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}

void treeView1_HandleCreated(object sender, EventArgs e)
{
Console.WriteLine("HandleCreated");
}

void treeView1_HandleDestroyed(object sender, EventArgs e)
{
Console.WriteLine("HandleDestroyed");
}

void treeView1_AfterCollapse(object sender, TreeViewEventArgs e)
{
Console.WriteLine("AfterCollapse");
}

void treeView1_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
{
Console.WriteLine("AfterCollapse");
}
}
}
Aug 9 '07 #1
0 1396

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

Similar topics

1
by: | last post by:
This could possibly be a bug, but I don't understand it fully so I'm posting here first. Searching the list told me other people are having this problem too. I have created a class which...
3
by: SK | last post by:
I have a file. i get the creation time using File.GetCreationTime. then i go and delete that file. and then create it again and print the File.GetCreationTime. It is giving me the old creation...
2
by: pantagruel | last post by:
I have an old web application I did where browsers with dynamic capabilities received a drop down menu on the top of the page and a fold out on the left hand side of the page and non-dynamic...
1
by: Ken Dopierala Jr. | last post by:
Hi, I'm creating some large custom controls and I'm getting annoyed by all the markup they create. Is there a #Region equivilant for HTML in .aspx pages to expand and collapse it? If not, is...
5
by: Parapura Rajkumar | last post by:
hey all class A { }; class B {
10
by: brooksr | last post by:
I know VB5/VBA very well but have not used VB to create web pages but need to do so. Can someone explain the purposes and differences between VBScript and VB.NET to create web pages? Also...
2
by: Joe Stateson | last post by:
Not sure what is going on. I have a treeview of an XmlDataSource with cacheing enabled. With only a few nodes there is no problem on a postback, the treeview is repainted immediately. With a lot...
5
by: cctv.star | last post by:
I need to maintain certain data structure, shared by all instances of a class, declared as . This data structure must change whenever a new object is created or an existing object is destroyed. So...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.