Treeview implementation similar to outlook display the number of new mails behind the inbox

Source: Internet
Author: User
After receiving a new email, outlook and Foxmail will display the number of new emails after the Inbox: inbox (1) . We sometimes need similar functions when doing applications, such as the number of warning messages displayed in alarm management. How can this problem be achieved? After reading the treeveiw and treenode attributes and methods, we did not find any direct implementation. We did not find any on Google or Baidu. However, the Treeview control has a drawnode event, which allows you to draw nodes by yourself and implement the desired function: inbox. (1) . I think other friends may also be thinking about how to implement this function. Share it with me so that you can avoid detours.

Effect:

Implementation Code : Private   Void Form1_load ( Object Sender, eventargs E)
{
Treenode Root =   New Treenode ( " Myname@163.com " );
Root. Name =   " Root " ;
Root. nodes. Add ( " Inbox " , " Inbox " );
Root. nodes. Add ( " Outbox " , " Sender " );
Root. nodes. Add ( " Sentbox " , " Sent Email Addresses " );
Root. nodes. Add ( " Spam " , " Spam " );
Root. nodes. Add ( " Trashbox " , " Waste case box " );
This . Treeview1.nodes. Add (Root );
This . Treeview1.expandall ();

//Set the painting mode to ownerdrawtext:
//Manually draw the label part of the node, and draw the other part of the system.
Treeview1.drawmode=Treeviewdrawmode. ownerdrawtext;
}

Private   Void Treeviewmediadrawnode ( Object Sender, drawtreenodeeventargs E)
{
// Drawn by System
E. drawdefault =   True ;
// Draw "Number of new mails" behind the node ". For example: inbox (3)
If (E. node. Tag ! =   Null )
{
String Newmail =   String . Format ( " ({0 }) " , E. node. Tag. tostring ());
E. Graphics. drawstring (newmail, E. node. Treeview. Font, brushes. Blue, E. bounds. Right, E. bounds. Top );
}
}

Private   Void Newmailbutton_click ( Object Sender, eventargs E)
{
Treenode inboxnode =   This . Treeview1.nodes [ " Root " ]. Nodes [ " Inbox " ];
Inboxnode. Tag =   " 3 " ;
This . Treeview1.refresh ();
}

Private   Void Readmailbutton_click ( Object Sender, eventargs E)
{
Treenode inboxnode =   This . Treeview1.nodes [ " Root " ]. Nodes [ " Inbox " ];
Inboxnode. Tag =   Null ;
This . Treeview1.refresh ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.