473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1416

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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.