private TreeListNodeCollection GetSelectedNodes(TreeListNode node)
        {
            TreeListNodeCollection list = new TreeListNodeCollection();

            for (int i=0; i<node.Nodes.Count; i++)
            {
                // check if current node is selected
                if (node.Nodes[i].Selected)
                {
                    list.Add(node.Nodes[i]);
                }

                // chech if node is expanded and has
                // selected children
                if (node.Nodes[i].IsExpanded)
                {
                    TreeListNodeCollection list2 = GetSelectedNodes(node.Nodes[i]);
                    for (int j=0; j<list2.Count; j++)
                    {
                        list.Add(list2[i]);
                    }
                }
            }

            return list;
        }
 private string GetFullPath(TreeListNode item)
 {
     if (item.Parent == null)
     {
         return item.Text;
     }
     else if (item.Parent.Tag == null)
     {
         return item.Text;
     }
     else
     {
         return item.Parent.FullPath + "\\" + item.Text;
     }
 }
        public override bool PreProcessMessage(ref Message msg)
        {
            if (msg.Msg == WM_KEYDOWN)
            {
                if (nodes.Count > 0)
                {
                    if (curNode != null)
                    {
                        Keys keyData = ((Keys) (int) msg.WParam) | ModifierKeys;
                        Keys keyCode = ((Keys) (int) msg.WParam);

                        if (keyCode == Keys.Left)	// collapse current node or move up to parent
                        {
                            if (curNode.IsExpanded)
                            {
                                curNode.Collapse();
                            }
                            else if (curNode.ParentNode() != null)
                            {
                                TreeListNode t = (TreeListNode)curNode.ParentNode();
                                if (t.ParentNode() != null) // never select virtualParent node
                                {
                                    if (!multiSelect)
                                        curNode.Selected = false;
                                    //else
                                    curNode.Focused = false;
                                    curNode = (TreeListNode)curNode.ParentNode();
                                    if (!multiSelect)
                                    {
                                        curNode.Selected = true;
                                        this.SelectedNode = curNode;
                                    }
                                    //else
                                    curNode.Focused = true;
                                    this.SelectedNode = curNode;
                                }
                            }

                            Invalidate();
                            return true;
                        }
                        else if (keyCode == Keys.Right) // expand current node or move down to first child
                        {
                            if (!curNode.IsExpanded)
                            {
                                curNode.Expand();
                            }
                            else if (curNode.IsExpanded && curNode.GetNodeCount(false) > 0)
                            {
                                if (!multiSelect)
                                    curNode.Selected = false;
                                //else
                                curNode.Focused = false;
                                curNode = (TreeListNode)curNode.FirstChild();
                                if (!multiSelect)
                                    curNode.Selected = true;
                                //else
                                curNode.Focused = true;
                                this.SelectedNode = curNode;
                            }

                            Invalidate();
                            return true;
                        }

                        else if (keyCode == Keys.Up)
                        {
                            if (curNode.PreviousSibling() == null && curNode.ParentNode() != null)
                            {
                                TreeListNode t = (TreeListNode)curNode.ParentNode();
                                if (t.ParentNode() != null) // never select virtualParent node
                                {
                                    if (!multiSelect)
                                        curNode.Selected = false;
                                    //else
                                    curNode.Focused = false;
                                    curNode = (TreeListNode)curNode.ParentNode();
                                    if (!multiSelect)
                                        curNode.Selected = true;
                                    //else
                                    curNode.Focused = true;
                                    this.SelectedNode = curNode;
                                }

                                Invalidate();
                                return true;
                            }
                            else if (curNode.PreviousSibling() != null)
                            {
                                TreeListNode t = (TreeListNode)curNode.PreviousSibling();
                                if (t.GetNodeCount(false) > 0 && t.IsExpanded)
                                {
                                    do
                                    {
                                        t = (TreeListNode)t.LastChild();
                                        if (!t.IsExpanded)
                                        {
                                            if (!multiSelect)
                                                curNode.Selected = false;
                                            //else
                                            curNode.Focused = false;
                                            curNode = t;
                                            if (!multiSelect)
                                                curNode.Selected = true;
                                            //else
                                            curNode.Focused = true;
                                            this.SelectedNode = curNode;
                                        }
                                    } while (t.GetNodeCount(false) > 0 && t.IsExpanded);
                                }
                                else
                                {
                                    if (!multiSelect)
                                        curNode.Selected = false;
                                    //else
                                    curNode.Focused = false;
                                    curNode = (TreeListNode)curNode.PreviousSibling();
                                    if (!multiSelect)
                                        curNode.Selected = true;
                                    //else
                                    curNode.Focused = true;
                                    this.SelectedNode = curNode;
                                }

                                Invalidate();
                                return true;
                            }
                        }
                        else if (keyCode == Keys.Down)
                        {
                            if (curNode.IsExpanded && curNode.GetNodeCount(false) > 0)
                            {
                                if (!multiSelect)
                                    curNode.Selected = false;
                                //else
                                curNode.Focused = false;
                                curNode = (TreeListNode)curNode.FirstChild();
                                if (!multiSelect)
                                {
                                    curNode.Selected = true;
                                    this.SelectedNode = curNode;
                                }
                                //else
                                curNode.Focused = true;
                            }
                            else if (curNode.NextSibling() == null && curNode.ParentNode() != null)
                            {
                                TreeListNode t = curNode;
                                do
                                {
                                    t = (TreeListNode)t.ParentNode();
                                    if (t.NextSibling() != null)
                                    {
                                        if (!multiSelect)
                                            curNode.Selected = false;
                                        //else
                                        curNode.Focused = false;
                                        curNode = (TreeListNode)t.NextSibling();
                                        if (!multiSelect)
                                            curNode.Selected = true;
                                        //else
                                        curNode.Focused = true;
                                        this.SelectedNode = curNode;
                                        break;
                                    }
                                } while (t.NextSibling() == null && t.ParentNode() != null);
                            }
                            else if (curNode.NextSibling() != null)
                            {
                                if (!multiSelect)
                                    curNode.Selected = false;
                                //else
                                curNode.Focused = false;
                                curNode = (TreeListNode)curNode.NextSibling();
                                if (!multiSelect)
                                    curNode.Selected = true;
                                //else
                                curNode.Focused = true;
                                this.SelectedNode = curNode;
                            }

                            Invalidate();
                            return true;
                        }
                    }
                }
            }

            return base.PreProcessMessage(ref msg);
        }
        public new void EnsureVisible(TreeListNode node)
        {
            b_fand = false;
            int nodePos = GetTreeListNodePos(node);
            int value = itemheight * nodePos;

            if (value < vscrollBar.Value)
            {
                int min = vscrollBar.Minimum;
                int v = value;
                if (v < min) v = min;
                vscrollBar.Value = v;
            }
            else if (value > vscrollBar.Value + vscrollBar.Height)
            {
                int max = vscrollBar.Maximum;
                int v = value - vscrollBar.Height + itemheight;
                if (v > max) v = max;
                vscrollBar.Value = v;
            }
        }
        public void Insert(int pos, TreeListNode item)
        {
            item.MouseDown += new MouseEventHandler(OnMouseDown);
            item.Nodes.NodesChanged += new EventHandler(OnNodesChanged);
            item.Parent = owner;
            item.FullPath = GetFullPath(item);
            //    OnNodesChanged();
            List.Insert(pos, item);
            //return item.Index = List.Add(item);

            //Add By T.L
            for (int i = pos; i < List.Count; i++)
            {
                TreeListNode node = (TreeListNode)List[i];
                node.Index = i;
            }
        }
 public TreeListNodeCollection(TreeListNode owner)
 {
     this.owner = owner;
 }
 //��TreeListNodeCollection�м����е�Node
 public int Add(TreeListNode item, Boolean bz)
 {
     if (bz)
     {
         item.MouseDown += new MouseEventHandler(OnMouseDown);
         item.Nodes.NodesChanged += new EventHandler(OnNodesChanged);
         item.Parent = owner;
         item.FullPath = GetFullPath(item);
         OnNodesChanged();
         return item.Index = List.Add(item);
     }
     else
     {
         return item.Index = List.Add(item);
     }
 }
        private void LoadCalendarYearView()
        {
            int year = currentTime.Year;

            int nowYearsDay = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInYear(year);

            lfWidth = 52;
            nodes.Clear();

            int startIndex = 0;
            for (int m = 1; m <= 12;m++ )
            {
                int month = m;
                int nowMonthDays = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(year, month);

                for (int i = 1; i <= nowMonthDays; i++)
                {
                    TreeListNode dtNode = new TreeListNode(new DateTime(year, month, i, 0, 0, 0));
                    nodes.Add(dtNode);
                }

                int firstDayWeek = nodes[startIndex].Week;
                int lastDayWeek = nodes[nowMonthDays - 1].Week;

                if(firstDayWeek!=0)
                {
                    for (int i = 0; i < firstDayWeek; i++)
                    {
                        DateTime dtLastMonthFirst = nodes[startIndex].Date.AddDays(-1);
                        TreeListNode dtNode = new TreeListNode(dtLastMonthFirst);
                        dtNode.IsBlankNode = true;
                        dtNode.BackColor = Color.LightGray;
                        nodes.Insert(startIndex, dtNode);
                    }
                }
                int monthNodeCount = nodes.Count - startIndex;
                if(monthNodeCount<37)
                {
                    for(int i=0;i<37-monthNodeCount;i++)
                    {
                        DateTime dtLastMonthDay = nodes[nodes.Count - 1].Date.AddDays(1);
                        TreeListNode dtNode = new TreeListNode(dtLastMonthDay);
                        dtNode.IsBlankNode = true;
                        dtNode.BackColor = Color.LightGray;
                        nodes.Add(dtNode);
                    }
                }
                startIndex = nodes.Count;
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                int row = i / 37;
                int col = i % 37;
                nodes[i].Row = row;
                nodes[i].Col = col;
            }
            BindTaskToNode();
            Invalidate();

            //������ǰ��ͼʱ��
            minTime = nodes[0].Date;
            maxTime = nodes[nodes.Count - 1].Date;

            foreach (TreeListNode node in nodes)
            {
                if (node.Date.Day == currentTime.Day &&node.Date.Year == currentTime.Year && node.Date.Month == currentTime.Month)
                {
                    node.Focused = true;
                    node.Selected = true;
                    this.SelectedNode = node;
                    //selectedNode = node;
                    break;
                }
            }
        }
        private void RenderMonthDateNode(TreeListNode node, Graphics g, Rectangle r, int level)
        {
            //��λ�������ڵ�λ��
            int row =node.Row;  //����������
            int col = node.Col;  //����������

            if(row==5)
            {

            }
            int lb = lfWidth;
            int hb = headerBuffer;
            int tb = 1;
            Rectangle sr = new Rectangle(r.Left + (int)(itemwidth * col) + lb - hscrollBar.Value, r.Top + itemheight * row + tb + hb - vscrollBar.Value, (int)itemwidth, itemheight);
            if(col == colCount-1 && sr.Right<r.Right)
            {
                sr = new Rectangle(sr.Left, sr.Top, sr.Width + (r.Right - sr.Right), sr.Height);
            }

            nodeRowRects.Add(sr, node);

            g.Clip = new Region(sr);
            //����������򱳾���ɫ
            g.FillRectangle(new SolidBrush(node.BackColor), sr);
            //g.DrawRectangle(Pens.Black, sr);
            //������������߿�
            if(row!=0)
                g.DrawLine(Pens.Black, sr.Left, sr.Top, sr.Right, sr.Top);
            if(col!=0)
                g.DrawLine(Pens.Black, sr.Left, sr.Top, sr.Left, sr.Bottom);
            g.DrawLine(Pens.Black, sr.Right, sr.Top, sr.Right, sr.Bottom);
            g.DrawLine(Pens.Black, sr.Left, sr.Bottom, sr.Right, sr.Bottom);

            //���������ı���Ϣ
            if (calendarViewMode == CalendarViewModel.Month)
            {
                //����ѡ�нڵ�
                if (node.Selected)
                {
                    g.FillRectangle(new SolidBrush(rowSelectColor), sr.Left + 2, sr.Top + 2, sr.Width - 2, 22);
                }
                Font textFont = new Font("΢���ź�", 10.0f);
                //1. ����
                string daytext = node.Day.ToString();
                if (node.Day == 1)
                {
                    daytext = node.Month + "��, 1";
                }
                if (node.Month == 1 && node.Day == 1)
                {
                    daytext = node.Year + "��, " + node.Month + "��, 1";
                }
                if (node.IsToday)
                {
                    textFont = new Font("΢���ź�", 10.0f, FontStyle.Bold);
                    daytext = daytext + ", ����";
                }
                if (node.Selected)
                    g.DrawString(daytext, textFont, rowSelectBrush, (float)(sr.Left + 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));
                else
                    g.DrawString(daytext, textFont, new SolidBrush(node.ForeColor), (float)(sr.Left + 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));
                //2. ũ������
                string dayCN = node.ChinesDate.Cday;
                if (dayCN == "��һ")
                {
                    dayCN = node.ChinesDate.Cmonth + "��"; // node.ChinesDate.Cday;
                }
                SizeF strSize = TextRenderer.MeasureText(g, dayCN, textFont, new Size(0, 0), TextFormatFlags.NoPadding);
                if (node.Selected)
                    g.DrawString(dayCN, textFont, rowSelectBrush, (float)(sr.Right - strSize.Width - 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));
                else
                    g.DrawString(dayCN, textFont, new SolidBrush(node.ForeColor), (float)(sr.Right - strSize.Width - 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));

            }
            else if(calendarViewMode== CalendarViewModel.Year)
            {
                if (node.Row == node.Date.Month - 1) //����
                {
                    //����ѡ�нڵ�
                    if (node.Selected)
                    {
                        g.FillRectangle(new SolidBrush(rowSelectColor), sr.Left + 2, sr.Top + 2, sr.Width - 2, 22);
                    }
                    Font textFont = new Font("΢���ź�", 9.0f);
                    //1. ����
                    string daytext = node.Day.ToString();
                    if (node.IsToday)
                    {
                        textFont = new Font("΢���ź�", 9.0f, FontStyle.Bold);
                        //daytext = daytext + "����";

                    }
                    if (node.Selected)
                        g.DrawString(daytext, textFont, rowSelectBrush, (float)(sr.Left + 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));
                    else
                        g.DrawString(daytext, textFont, new SolidBrush(node.ForeColor), (float)(sr.Left + 4 - hscrollBar.Value), (float)(sr.Top + 4 - vscrollBar.Value));

                }
                else
                {

                }

            }
        }
        private void LoadCalendarTimeSpanView()
        {
            itemwidth = 25;
            int nodeCount = this.Width / (int)itemwidth + 2;

            DateTime dtStart = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second);

            lfWidth = 0;
            nodes.Clear();
            for (int i = 0; i < nodeCount; i++)
            {
                DateTime dt = dtStart.AddMinutes(30 * i);
                TreeListNode dtNode = new TreeListNode(dt);
                if((dt.Hour==23 && dt.Minute==30) || (dt.Hour==0 && dt.Minute==0))
                {
                    dtNode.BackColor = Color.LightYellow;
                }
                nodes.Add(dtNode);
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].Row = 0;
                nodes[i].Col = i;
            }
            BindTaskToNode();
            Invalidate();

            //������ǰ��ͼʱ��
            minTime = nodes[0].Date;
            maxTime = nodes[nodes.Count - 1].Date;

            foreach (TreeListNode node in nodes)
            {
                //��ǰʱ��
                if (node.Date.Day == currentTime.Day && node.Date.Hour == DateTime.Now.Hour && node.Date.Year == currentTime.Year && node.Date.Month == currentTime.Month)
                {
                    node.Focused = true;
                    node.Selected = true;
                    this.SelectedNode = node;
                    //selectedNode = node;
                    break;
                }
            }
        }
        private void LoadCalendarWeekView(int dayCount)
        {
            DateTime startDayTime = DateTime.Now;
            if(dayCount==1)  //һ��
            {
                startDayTime = currentTime;
            }
            else if(dayCount==31)  //һ����
            {
                int year = currentTime.Year;
                int month = currentTime.Month;
                int nowMonthDays = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(year, month);
                startDayTime = new DateTime(year, month, 1);
                dayCount = nowMonthDays;
            }
            else if(dayCount==5) //������
            {
                startDayTime = currentTime.AddDays(1 - Convert.ToInt32(currentTime.DayOfWeek.ToString("d")));
            }
            else if(dayCount==7)  //��
            {
                startDayTime = currentTime.AddDays(1 - Convert.ToInt32(currentTime.DayOfWeek.ToString("d")));
            }
            int week = GetWeekOfYear(currentTime);

            lfWidth = 60;
            itemheight = 20;
            nodes.Clear();
            int i = 0;
            for (i = 0; i < dayCount; i++)
            {
                DateTime dt = startDayTime.AddDays(i);
                for(int j=0;j<24;j++)
                {
                    TreeListNode dtNode1 = new TreeListNode(new DateTime(dt.Year, dt.Month, dt.Day,j,0,0));
                    dtNode1.Row = j * 2;
                    dtNode1.Col = i;
                    nodes.Add(dtNode1);
                    TreeListNode dtNode2 = new TreeListNode(new DateTime(dt.Year, dt.Month, dt.Day, j, 30, 0));
                    dtNode2.Row = j * 2+1;
                    dtNode2.Col = i;
                    nodes.Add(dtNode2);
                    if (dtNode1.Week == 6 || dtNode1.Week == 0)
                    {
                        dtNode1.BackColor = Color.LightYellow;
                        dtNode2.BackColor = Color.LightYellow;
                    }
                }
            }
            BindTaskToNode();
            RefreshTaskEvent();
            Invalidate();

            //������ǰ��ͼʱ��
            minTime = nodes[0].Date;
            maxTime = nodes[nodes.Count - 1].Date;

            foreach (TreeListNode node in nodes)
            {
                if (node.Date.Day == currentTime.Day && node.Date.Hour == currentTime.Hour && node.Date.Year == currentTime.Year && node.Date.Month == currentTime.Month)
                {
                    node.Focused = true;
                    node.Selected = true;
                    this.SelectedNode = node;
                    //selectedNode = node;
                    break;
                }
            }
        }
        private void LoadCalendarMonthView()
        {
            int year = currentTime.Year;
            int month = currentTime.Month;

            lfWidth = 0;

            nodes.Clear();
            int nowMonthDays = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(year, month);

            for (int i = 1; i <= nowMonthDays; i++)
            {
                TreeListNode dtNode = new TreeListNode(new DateTime(year, month, i,0,0,0));
                nodes.Add(dtNode);
            }
            int firstDayWeek = nodes[0].Week;
            int lastDayWeek = nodes[nowMonthDays - 1].Week;
            //��һ�ܵ�����
            if (firstDayWeek != 0)
            {
                for (int i = 0; i < firstDayWeek; i++)
                {
                    DateTime dtLastMonthFirst = nodes[0].Date.AddDays(-1);
                    TreeListNode dtNode = new TreeListNode(dtLastMonthFirst);
                    dtNode.BackColor = Color.LightYellow;
                    nodes.Insert(0, dtNode);
                }
            }
            //���һ�ܵ�����
            if (lastDayWeek != 6)
            {
                for (int i = lastDayWeek + 1; i < 7; i++)
                {
                    DateTime dtLastMonthDay = nodes[nodes.Count - 1].Date.AddDays(1);
                    TreeListNode dtNode = new TreeListNode(dtLastMonthDay);
                    dtNode.BackColor = Color.LightYellow;
                    nodes.Add(dtNode);
                }
            }
            for (int i = 0; i < nodes.Count; i++)
            {
                int row = i / 7;
                int col = i % 7;
                nodes[i].Row = row;
                nodes[i].Col = col;
            }
            BindTaskToNode();
            Invalidate();

            //������ǰ��ͼʱ��
            minTime = nodes[0].Date;
            maxTime = nodes[nodes.Count - 1].Date;

            foreach(TreeListNode node in nodes)
            {
                if(node.Date.Day== currentTime.Day && node.Date.Year== currentTime.Year && node.Date.Month== currentTime.Month)
                {
                    node.Focused = true;
                    node.Selected = true;
                    this.SelectedNode = node;
                    //selectedNode = node;
                    break;
                }
            }
        }
        private int GetTreeListNodePos(TreeListNode n, TreeListNode node)
        {
            int allShowNodes = 1;
            for (int i = 0; i < n.Nodes.Count; i++)
            {
                TreeListNode tn = n.Nodes[i];
                if (tn == node)
                {
                    b_fand = true;
                    return allShowNodes;
                }
                if (b_fand) break;
                if (tn.IsExpanded && tn.Nodes.Count > 0)
                {
                    allShowNodes += GetTreeListNodePos(tn, node);
                }
                else
                {
                    allShowNodes++;
                }
            }

            return allShowNodes;
        }
 private int GetTreeListNodePos(TreeListNode node)
 {
     int allShowNodes = 0;
     for (int i = 0; i < nodes.Count; i++)
     {
         TreeListNode n = nodes[i];
         if (n == node) return allShowNodes;
         if (b_fand) break;
         if (n.IsExpanded && n.Nodes.Count > 0)
         {
             allShowNodes += GetTreeListNodePos(n, node);
         }
         else
         {
             allShowNodes++;
         }
     }
     return allShowNodes;
 }
 public object PreviousChild()
 {
     curChild = (TreeListNode)curChild.PreviousSibling();
     return curChild;
 }
        //private void RenderNodeRows(TreeListNode node, Graphics g, Rectangle r, int level, int index, ref int totalRend, ref int childCount, int count)
        //{
        //    g.DrawString(node.Date.ToString(), Font, new SolidBrush(node.ForeColor), 12, (float)(r.Top + 30 + itemheight * index - vscrollBar.Value));
        //    return;
        //    if (node.IsVisible)
        //    {
        //        int eb = 10;	// edge buffer
        //        // only render if row is visible in viewport
        //        if (((r.Top + itemheight * totalRend + eb / 4 - vscrollBar.Value + itemheight > r.Top)
        //            && (r.Top + itemheight * totalRend + eb / 4 - vscrollBar.Value < r.Top + r.Height)))
        //        {
        //            rendcnt++;
        //            int lb = 0;		// level buffer
        //            int ib = 0;		// icon buffer
        //            int hb = headerBuffer;	// header buffer
        //            Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f);
        //            Pen PMPen = new Pen(SystemBrushes.ControlDark, 1.0f);
        //            Pen PMPen2 = new Pen(new SolidBrush(Color.Black), 1.0f);
        //            linePen.DashStyle = DashStyle.Dot;
        //            // add space for plis/minus icons and/or root lines to the edge buffer
        //            if (showrootlines || showplusminus)
        //            {
        //                eb += 10;
        //            }
        //            // set level buffer
        //            lb = indent * level;
        //            // set icon buffer
        //            if ((node.Selected || node.Focused) && stateImageList != null)
        //            {
        //                if (node.ImageIndex >= 0 && node.ImageIndex < stateImageList.Images.Count)
        //                {
        //                    stateImageList.Draw(g, r.Left + lb + eb + 2 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + eb / 4 - 2 - vscrollBar.Value, 16, 16, node.ImageIndex);
        //                }
        //            }
        //            else
        //            {
        //                if (smallImageList != null && node.ImageIndex >= 0 && node.ImageIndex < smallImageList.Images.Count)
        //                {
        //                    //�ж��Ƿ�ڵ㱻ѡ��,ѡ����StateImageIndexͼ��;
        //                    if (node.IsExpanded)
        //                    {
        //                        smallImageList.Draw(g, r.Left + lb + eb + 2 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + eb / 4 - 2 - vscrollBar.Value, smallImageList.ImageSize.Width, 16, node.SelectedImageIndex);
        //                        ib = smallImageList.ImageSize.Width+2;
        //                    }
        //                    else
        //                    {
        //                        smallImageList.Draw(g, r.Left + lb + eb + 2 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + eb / 4 - 2 - vscrollBar.Value, smallImageList.ImageSize.Width, 16, node.ImageIndex);
        //                        ib = smallImageList.ImageSize.Width + 2;
        //                    }
        //                }
        //            }
        //            // add a rectangle to the node row rectangles
        //            Rectangle sr = new Rectangle(r.Left + lb + ib + eb + 4 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + 2 - vscrollBar.Value, allColsWidth - (lb + ib + eb + 4), itemheight);
        //            if (gridStyle)
        //            {
        //                sr.X = 2;
        //            }
        //            nodeRowRects.Add(sr, node);
        //            g.Clip = new Region(sr);
        //            // render per-item background
        //            if (node.BackColor != this.BackColor)
        //            {
        //                if (node.UseItemStyleForSubItems)
        //                {
        //                    if (editStyle)
        //                    {
        //                        g.FillRectangle(new SolidBrush(node.BackColor), r.Left + 4 + this.columns[0].Width - hscrollBar.Value, r.Top + hb + itemheight * totalRend + 2 - vscrollBar.Value, allColsWidth - (lb + ib + eb + 4), itemheight);
        //                    }
        //                    else
        //                    {
        //                        g.FillRectangle(new SolidBrush(node.BackColor), r.Left + lb + ib + eb + 4 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + 2 - vscrollBar.Value, allColsWidth - (lb + ib + eb + 4), itemheight);
        //                    }
        //                }
        //                else
        //                {
        //                    g.FillRectangle(new SolidBrush(node.BackColor), r.Left + lb + ib + eb + 4 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + 2 - vscrollBar.Value, columns[0].Width - (lb + ib + eb + 4), itemheight);
        //                    // return;
        //                }
        //            }
        //            if (node.BackColor != this.BackColor)
        //            {
        //                g.FillRectangle(new SolidBrush(node.BackColor), sr);
        //            }
        //            // render selection and focus
        //            if (node.Selected && isFocused)
        //            {
        //                g.FillRectangle(new SolidBrush(rowSelectColor), sr);
        //                if (this.rowSelectColor != Color.Transparent)
        //                {
        //                    g.FillRectangle(new SolidBrush(rowSelectColor), sr);
        //                }
        //                else
        //                {
        //                    ControlPaint.DrawFocusRectangle(g, sr);
        //                }
        //            }
        //            else if (node.Selected && !isFocused && !hideSelection)
        //            {
        //                g.FillRectangle(SystemBrushes.Control, sr);
        //            }
        //            else if (node.Selected && !isFocused && hideSelection)
        //            {
        //                ControlPaint.DrawFocusRectangle(g, sr);
        //            }
        //            if (node.Focused && ((isFocused && multiSelect) || !node.Selected))
        //            {
        //                ControlPaint.DrawFocusRectangle(g, sr);
        //            }
        //            //��ѡ�нڵ㱳��;
        //            //if (this.selectedNode != null)
        //            //{
        //            //    if (this.SelectedNode.Selected && isFocused && !hideSelection)
        //            //    {
        //            //        ControlPaint.DrawFocusRectangle(g, sr);
        //            //    }
        //            //}
        //            g.Clip = new Region(new Rectangle(r.Left + 2 - hscrollBar.Value, r.Top + hb + 2, columns[0].Width, r.Height - hb - 4));
        //            // render root lines if visible
        //            if (r.Left + eb - hscrollBar.Value > r.Left)
        //            {
        //                if (showrootlines && level == 0)
        //                {
        //                    if (index == 0)
        //                    {
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb - vscrollBar.Value, r.Left + eb - hscrollBar.Value, r.Top + eb / 2 + hb - vscrollBar.Value);
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb - vscrollBar.Value, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb + hb - vscrollBar.Value);
        //                    }
        //                    else if (index == count - 1)
        //                    {
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + eb - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                    }
        //                    else
        //                    {
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb + hb + itemheight * (totalRend) - eb / 2 - vscrollBar.Value, r.Left + eb - hscrollBar.Value, r.Top + eb + hb + itemheight * (totalRend) - eb / 2 - vscrollBar.Value);
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb + hb + itemheight * (totalRend - 1) - vscrollBar.Value, r.Left + eb / 2 - hscrollBar.Value, r.Top + eb + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                    }
        //                    if (childCount > 0)
        //                        g.DrawLine(linePen, r.Left + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend - childCount) - vscrollBar.Value, r.Left + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                }
        //            }
        //            // render child lines if visible
        //            if (r.Left + lb + eb - hscrollBar.Value > r.Left)
        //            {
        //                if (showlines && level > 0)
        //                {
        //                    if (index == count - 1)
        //                    {
        //                        g.DrawLine(linePen, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + lb + eb - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                        g.DrawLine(linePen, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                    }
        //                    else
        //                    {
        //                        g.DrawLine(linePen, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + lb + eb - hscrollBar.Value, r.Top + eb / 2 + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                        g.DrawLine(linePen, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend) - vscrollBar.Value, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + eb + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                    }
        //                    if (childCount > 0)
        //                        g.DrawLine(linePen, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend - childCount) - vscrollBar.Value, r.Left + lb + eb / 2 - hscrollBar.Value, r.Top + hb + itemheight * (totalRend) - vscrollBar.Value);
        //                }
        //            }
        //            // render +/- signs if visible
        //            if (r.Left + lb + eb / 2 + 5 - hscrollBar.Value > r.Left)
        //            {
        //                if (showplusminus && (node.GetNodeCount(false) > 0 || alwaysShowPM))
        //                {
        //                    if (index == 0 && level == 0)
        //                    {
        //                        RenderPlus(g, r.Left + lb + eb / 2 - 4 - hscrollBar.Value, r.Top + hb + eb / 2 - 4 - vscrollBar.Value, 8, 8, node);
        //                    }
        //                    else if (index == count - 1)
        //                    {
        //                        RenderPlus(g, r.Left + lb + eb / 2 - 4 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + eb / 2 - 4 - vscrollBar.Value, 8, 8, node);
        //                    }
        //                    else
        //                    {
        //                        RenderPlus(g, r.Left + lb + eb / 2 - 4 - hscrollBar.Value, r.Top + hb + itemheight * totalRend + eb / 2 - 4 - vscrollBar.Value, 8, 8, node);
        //                    }
        //                }
        //            }
        //            // render text if visible
        //            if (r.Left + columns[0].Width - hscrollBar.Value > r.Left)
        //            {
        //                Font textFont = Font;
        //                if (gridStyle)
        //                {
        //                     textFont = new Font(Font.FontFamily, Font.Size, FontStyle.Bold);
        //                }
        //                if (columns[0].TextAlign == HorizontalAlignment.Left)
        //                {
        //                    if (node.Selected && isFocused)
        //                        g.DrawString(TruncatedString(node.Date.ToString(), columns[0].Width, lb + eb + ib + 6, g), textFont, rowSelectBrush, (float)(r.Left + lb + ib + eb + 4 - hscrollBar.Value), (float)(r.Top + hb + itemheight * totalRend + eb / 4 - vscrollBar.Value));
        //                    else
        //                        g.DrawString(TruncatedString(node.Text, columns[0].Width, lb + eb + ib + 6, g), textFont, new SolidBrush(node.ForeColor), (float)(r.Left + lb + ib + eb + 4 - hscrollBar.Value), (float)(r.Top + hb + itemheight * totalRend + eb / 4 - vscrollBar.Value));
        //                }
        //                else if (columns[0].TextAlign == HorizontalAlignment.Right)
        //                {
        //                    string sp = TruncatedString(node.Date.ToString(), columns[0].Width, lb + eb + ib + 6, g);
        //                    SizeF strSize = TextRenderer.MeasureText(g, sp, textFont, new Size(0, 0), TextFormatFlags.NoPadding);
        //                    if (node.Selected && isFocused)
        //                        g.DrawString(sp, textFont, rowSelectBrush, (float)(r.Left + columns[0].Width - strSize.Width - 4 - hscrollBar.Value), (float)(r.Top + hb + itemheight * totalRend + eb / 4 - vscrollBar.Value));
        //                    else
        //                        g.DrawString(sp, textFont, new SolidBrush(node.ForeColor), (float)(r.Left + columns[0].Width - strSize.Width - 4 - hscrollBar.Value), (float)(r.Top + hb + itemheight * totalRend + eb / 4 - vscrollBar.Value));
        //                }
        //            }
        //            // render subitems
        //            int j;
        //            int last = 0;
        //            if (columns.Count > 0)
        //            {
        //                for (j = 0; j < node.SubItems.Count && j < columns.Count; j++)
        //                {
        //                    last += columns[j].Width;
        //                    g.Clip = new Region(new Rectangle(last + 6 - hscrollBar.Value, r.Top + headerBuffer + 2, (last + columns[j + 1].Width > r.Width - 6 ? r.Width - 6 : columns[j + 1].Width - 6), r.Height - 5));
        //                    if (node.SubItems[j].ItemControl != null)
        //                    {
        //                        Control c = node.SubItems[j].ItemControl;
        //                        c.Location = new Point(r.Left + last + 4 - hscrollBar.Value, r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value);
        //                        c.ClientSize = new Size(columns[j + 1].Width - 6, rowHeight - 2);
        //                        if (node.Selected && isFocused)
        //                            c.BackColor = rowSelectColor;
        //                        else
        //                            c.BackColor = node.BackColor;
        //                        c.Parent = this;
        //                        c.Visible = true;
        //                    }
        //                    else if ( smallImageList != null && node.SubItems[j].ImageIndex>= 0 && node.SubItems[j].ImageIndex < smallImageList.Images.Count)
        //                    {
        //                        smallImageList.Draw(g, last + 6 - hscrollBar.Value, r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value, smallImageList.ImageSize.Width, 16, node.SubItems[j].ImageIndex);
        //                        if (node.Selected && isFocused)
        //                        {
        //                            g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g), this.Font, rowSelectBrush, (float)(last + 6 - hscrollBar.Value + smallImageList.ImageSize.Width+2), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                        }
        //                        else
        //                        {
        //                            g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g), this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last + 6 - hscrollBar.Value+ smallImageList.ImageSize.Width+2), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                        }
        //                    }
        //                    else
        //                    {
        //                        //��ɫ����ֻ������뵱ǰ������жϣ���Ϊ����Ա��д��붼�������ģ��͸��Ҷ���������ɫ�ж϶����Ӹ��Ӷ���
        //                        string sp = "";
        //                        if (columns[j + 1].TextAlign == HorizontalAlignment.Left)
        //                        {
        //                            if (node.Selected && isFocused)
        //                            {
        //                                //Add By T.L
        //                                List<int> colorIndex = node.SubItems[j].ColorIndex;
        //                                List<int> colorValue = node.SubItems[j].ColorValue;
        //                                if (colorIndex != null && node.SubItems[j].Text.Length > colorIndex[colorIndex.Count - 1])
        //                                {
        //                                    int x = (int)(last + 6 - hscrollBar.Value);
        //                                    int y = (int)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value);
        //                                    SizeF strSize;
        //                                    Color c = Color.Black;
        //                                    string ss = "";
        //                                    for (int i = 0; i < colorIndex.Count; ++i)
        //                                    {
        //                                        if (i == colorIndex.Count - 1)  //���һ��Index��ֱ�ӽ�ȡ���������ַ�
        //                                        {
        //                                            ss = node.SubItems[j].Text.Substring(colorIndex[i]);
        //                                        }
        //                                        else
        //                                        {
        //                                            ss = node.SubItems[j].Text.Substring(colorIndex[i], colorIndex[i + 1] - colorIndex[i]);
        //                                        }
        //                                        c = colorValue[i] == 0 ? node.ForeColor : Color.Red;
        //                                        //g.DrawString(ss, this.Font, new SolidBrush(c), x, y);
        //                                        TextRenderer.DrawText(g, ss, this.Font, new Point((int)x, (int)y), c);
        //                                        //strSize = g.MeasureString(ss, this.Font);
        //                                        strSize = TextRenderer.MeasureText(g, ss, this.Font, new Size(0, 0), TextFormatFlags.NoPadding);
        //                                        x += (int)strSize.Width;
        //                                    }
        //                                }
        //                                else
        //                                {
        //                                    g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g), this.Font, rowSelectBrush, (float)(last + 6 - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                                }
        //                            }
        //                            else
        //                            {
        //                                //Add By T.L
        //                                List<int> colorIndex = node.SubItems[j].ColorIndex;
        //                                List<int> colorValue = node.SubItems[j].ColorValue;
        //                                if (colorIndex != null && node.SubItems[j].Text.Length > colorIndex[colorIndex.Count - 1])
        //                                {
        //                                    int x = (int)(last + 6 - hscrollBar.Value);
        //                                    int y = (int)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value);
        //                                    SizeF strSize;
        //                                    Color c = Color.Black;
        //                                    string ss = "";
        //                                    for (int i = 0; i < colorIndex.Count; ++i)
        //                                    {
        //                                        if (i == colorIndex.Count - 1)  //���һ��Index��ֱ�ӽ�ȡ���������ַ�
        //                                        {
        //                                            ss = node.SubItems[j].Text.Substring(colorIndex[i]);
        //                                        }
        //                                        else
        //                                        {
        //                                            ss = node.SubItems[j].Text.Substring(colorIndex[i], colorIndex[i + 1] - colorIndex[i]);
        //                                        }
        //                                        c = colorValue[i] == 0 ? node.ForeColor : Color.Red;
        //                                        //g.DrawString(ss, this.Font, new SolidBrush(c), x, y);
        //                                        TextRenderer.DrawText(g, ss, this.Font, new Point(x, y), c);
        //                                        //strSize = g.MeasureString(ss, this.Font);
        //                                        strSize = TextRenderer.MeasureText(g, ss, this.Font, new Size(0, 0), TextFormatFlags.NoPadding);
        //                                        x += (int)strSize.Width;
        //                                    }
        //                                }
        //                                else
        //                                {
        //                                    g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g), this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last + 6 - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                                }
        //                            }
        //                        }
        //                        else if (columns[j + 1].TextAlign == HorizontalAlignment.Right)
        //                        {
        //                            sp = TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g);
        //                            if (node.Selected && isFocused)
        //                            {
        //                                g.DrawString(sp, this.Font, rowSelectBrush, (float)(last + columns[j + 1].Width - Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font) - 4 - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                            }
        //                            else
        //                            {
        //                                g.DrawString(sp, this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last + columns[j + 1].Width - Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font) - 4 - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                            }
        //                        }
        //                        else
        //                        {
        //                            sp = TruncatedString(node.SubItems[j].Text, columns[j + 1].Width, 9, g);
        //                            if (node.Selected && isFocused)
        //                                g.DrawString(sp, this.Font, SystemBrushes.HighlightText, (float)(last + (columns[j + 1].Width / 2) - (Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font) / 2) - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                            else
        //                                g.DrawString(sp, this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last + (columns[j + 1].Width / 2) - (Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font) / 2) - hscrollBar.Value), (float)(r.Top + (itemheight * totalRend) + headerBuffer + 4 - vscrollBar.Value));
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        // increment number of rendered nodes
        //        totalRend++;
        //        // render child nodes
        //        if (node.IsExpanded)
        //        {
        //            childCount = 0;
        //            for (int n=0; n<node.GetNodeCount(false); n++)
        //            {
        //                RenderNodeRows(node.Nodes[n], g, r, level+1, n, ref totalRend, ref childCount, node.Nodes.Count);
        //            }
        //        }
        //        childCount = node.GetVisibleNodeCount(true);
        //    }
        //    else
        //    {
        //        childCount = 0;
        //    }
        //}
        private void RenderPlus(Graphics g, int x, int y, int w, int h, TreeListNode node)
        {
            if (VisualStyles)
            {
                if (node.IsExpanded)
                    g.DrawImage(bmpMinus, x, y);
                else
                    g.DrawImage(bmpPlus, x, y);
            }
            else
            {
                g.DrawRectangle(new Pen(SystemBrushes.ControlDark),x, y, w, h);
                g.FillRectangle(new SolidBrush(Color.White), x+1, y+1, w-1, h-1);
                g.DrawLine(new Pen(new SolidBrush(Color.Black)), x+2, y+4, x+w-2, y+4);

                if (!node.IsExpanded)
                    g.DrawLine(new Pen(new SolidBrush(Color.Black)), x+4, y+2, x+4, y+h-2);
            }

            pmRects.Add(new Rectangle(x, y, w, h), node);
        }
 public void Remove()
 {
     int c = nodes.IndexOf(curChild);
     nodes.Remove(curChild);
     if (nodes.Count > 0 && nodes.Count > c)
         curChild = nodes[c];
     else
         curChild = nodes[nodes.Count];
 }
        private void RenderTimeSpanDateNode(TreeListNode node, Graphics g, Rectangle r, int level)
        {
            int row = node.Row;  //����������
            int col = node.Col;  //����������

            int lb = lfWidth;
            int hb = headerBuffer+ltHeight;
            int tb = 0;
            Rectangle sr = new Rectangle(r.Left + (int)(itemwidth * col) + lb - hscrollBar.Value, r.Top + itemheight * row + tb + hb - vscrollBar.Value, (int)itemwidth, itemheight);
            if (col == colCount - 1 && sr.Right < r.Right)
            {
                sr = new Rectangle(sr.Left, sr.Top, sr.Width + (r.Right - sr.Right), sr.Height);
            }

            nodeRowRects.Add(sr, node);

            g.Clip = new Region(sr);
            //����������򱳾���ɫ
            g.FillRectangle(new SolidBrush(node.BackColor), sr);
            if (node.Date.Hour == 23 && node.Date.Minute == 30)
            {
                g.DrawLine(Pens.SteelBlue, sr.Right - 1, sr.Top, sr.Right - 1, sr.Bottom);
            }

            //������������߿�
            if (row != 0)
                g.DrawLine(Pens.SteelBlue, sr.Left, sr.Top, sr.Right, sr.Top);
            if (col != 0)
                g.DrawLine(Pens.SteelBlue, sr.Left, sr.Top, sr.Left, sr.Bottom);
            g.DrawLine(Pens.SteelBlue, sr.Right, sr.Top, sr.Right, sr.Bottom);
            g.DrawLine(Pens.SteelBlue, sr.Left, sr.Bottom - 1, sr.Right, sr.Bottom - 1);

            //����ѡ�нڵ�
            if (node.Selected)
            {
                g.FillRectangle(new SolidBrush(rowSelectColor), sr.Left, sr.Top, sr.Width, sr.Height-2);
            }
        }
 public int this[TreeListNode item]
 {
     get { return List.IndexOf(item); }
 }
        private void RenderWeekDateNode(TreeListNode node, Graphics g, Rectangle r, int level)
        {
            int row = node.Row;  //����������
            int col = node.Col;  //����������

            int lb = lfWidth+1;
            int hb = headerBuffer + ltHeight;
            Rectangle sr = new Rectangle(r.Left + (int)(itemwidth * col) + lb - hscrollBar.Value, r.Top + itemheight * row + hb  +2-1- vscrollBar.Value, (int)itemwidth, itemheight);
            if (sr.Top > headerBuffer)
            {
                g.Clip = new Region(sr);
            }
            else
            {
                int d = headerBuffer + 1 - sr.Top;
                Rectangle rh = new Rectangle(sr.Left, sr.Top + d, sr.Width, sr.Height - d);
                g.Clip = new Region(rh);
            }

            if(col>5)
            {

            }

            if (sr.Top < headerBuffer) return;
            //Rectangle srNode = new Rectangle(sr.Left + 8, sr.Top, sr.Width - 8, sr.Height);
            Rectangle srNode = new Rectangle(sr.Left , sr.Top, sr.Width , sr.Height);
            nodeRowRects.Add(srNode, node);

            //����������򱳾���ɫ
            g.FillRectangle(new SolidBrush(node.BackColor), sr);
            //������������߿�

            Pen p = new Pen(Color.SaddleBrown);
            if(row%2==1)
            {
                p = new Pen(Color.NavajoWhite);
            }
            Pen pr = new Pen(Color.LightSteelBlue,1.0f);
            if(node.Week==0  || node.Week==5)
            {
                pr = new Pen(Color.SteelBlue, 1.0f);
            }
            g.FillRectangle(new SolidBrush(Color.White), sr.Left, sr.Top, 8, itemheight);
            if (row != 0)
                g.DrawLine(p, srNode.Left, srNode.Top, srNode.Right, srNode.Top);  //����
            //g.DrawLine(Pens.Black, srNode.Left, srNode.Top, srNode.Left, srNode.Bottom);  //���
            g.DrawLine(pr, srNode.Right - 1, srNode.Top, srNode.Right - 1, srNode.Bottom);   //�Ҳ�
            g.DrawLine(p, srNode.Left, srNode.Bottom, srNode.Right, srNode.Bottom);
            //����ѡ�нڵ�
            if (node.Selected)
            {
                g.FillRectangle(new SolidBrush(rowSelectColor), srNode.Left+1,srNode.Top,srNode.Width-2,srNode.Height);
            }
            else
            {
                //ControlPaint.DrawFocusRectangle(g, sr);
            }
        }
 public void AddRange(TreeListNode[] items)
 {
     lock(List.SyncRoot)
     {
         for (int i=0; i<items.Length; i++)
         {
             items[i].MouseDown += new MouseEventHandler(OnMouseDown);
             items[i].Nodes.NodesChanged+= new EventHandler(OnNodesChanged);
             items[i].Parent = owner;
             items[i].Index = List.Add(items[i]);
         }
         OnNodesChanged();
     }
 }
        private void SortNodes(TreeListNodeCollection lstNodes, int i)
        {
            foreach (TreeListNode treelistNode in lstNodes)
            {
                if (treelistNode.Nodes.Count > 0) SortNodes(treelistNode.Nodes, i);
            }

            //�����ڵ���������
            TreeListNode[] arrayNode = new TreeListNode[lstNodes.Count];
            for (int row = 0; row < lstNodes.Count; row++)
            {
                arrayNode[row] = lstNodes[row];
            }

            if (i == 0)
            {
                Array.Sort(arrayNode, delegate(TreeListNode node1, TreeListNode node2)
                {

                    if (sortAsc)
                    {
                        //����
                        if (regNumber.IsMatch(node1.Text) && regNumber.IsMatch(node2.Text))
                        {
                            return decimal.Parse(node1.Text).CompareTo(decimal.Parse(node2.Text));
                        }
                        else
                        {
                            return node1.Text.CompareTo(node2.Text);
                        }
                    }
                    else
                    {
                        //����
                        if (regNumber.IsMatch(node1.Text) && regNumber.IsMatch(node2.Text))
                        {
                            return decimal.Parse(node2.Text).CompareTo(decimal.Parse(node1.Text));
                        }
                        else
                        {
                            return node2.Text.CompareTo(node1.Text);
                        }
                    }
                });
            }
            else  //�Ƚϵ�subitems
            {
                Array.Sort(arrayNode, delegate(TreeListNode node1, TreeListNode node2)
                {
                    string text1 = "";
                    string text2 = "";
                    if (node1.SubItems.Count > i - 1)
                    {
                        text1 = node1.SubItems[i - 1].Text;
                    }
                    if (node2.SubItems.Count > i - 1)
                    {
                        text2 = node2.SubItems[i - 1].Text;
                    }

                    if (sortAsc)
                    {
                        //����
                        if (regNumber.IsMatch(text1) && regNumber.IsMatch(text2))
                        {
                            return decimal.Parse(text1).CompareTo(decimal.Parse(text2));
                        }
                        else
                        {
                            return text1.CompareTo(text2);
                        }
                    }
                    else
                    {
                        //����
                        if (regNumber.IsMatch(text1) && regNumber.IsMatch(text2))
                        {
                            return decimal.Parse(text2).CompareTo(decimal.Parse(text1));
                        }
                        else
                        {
                            return text2.CompareTo(text1);
                        }
                    }

                });  //�Զ�������ʽ
            }

            //�������Ľڵ�������ӵ�������
            for (int c = lstNodes.Count - 1; c >= 0; c--)
            {
                lstNodes.RemoveAt(c);
            }

            for (int c = 0; c < arrayNode.Length; c++)
            {
                lstNodes.Add(arrayNode[c]);
            }
        }
 public int IndexOf(TreeListNode item)
 {
     return List.IndexOf(item);
 }
 public object FirstChild()
 {
     curChild = Nodes[0];
     return curChild;
 }
        public void Remove(TreeListNode item)
        {
            List.Remove(item);

            //Add By T.L
            int pos = item.Index;

            for (int i = pos; i < List.Count; i++)
            {
                TreeListNode node = (TreeListNode)List[i];
                node.Index = i;
            }
        }
 public object LastChild()
 {
     curChild = Nodes[Nodes.Count-1];
     return curChild;
 }
 public int GetNodeCount(TreeListNode node)
 {
     int c = 0;
     c += node.Nodes.Count;
     foreach (TreeListNode n in node.Nodes)
     {
         c += GetNodeCount(n);
     }
     return c;
 }
 public object NextChild()
 {
     curChild = (TreeListNode)curChild.NextSibling();
     return curChild;
 }
        public CalendarView()
            : base()
        {
            virtualParent = new TreeListNode();

            nodes = virtualParent.Nodes;
            nodes.Owner = virtualParent;
            nodes.MouseDown += new MouseEventHandler(OnSubControlMouseDown);
            nodes.NodesChanged += new EventHandler(OnNodesChanged);

            taskEventNodes = new List<TaskEventNode>();
            selectedNodes = new TreeListNodeCollection();

            nodeRowRects = new ListDictionary();
            pmRects = new ListDictionary();

            txtNode = new TextBox();
            txtNode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            txtNode.MouseDown += txtNode_MouseDown;
            txtNode.MouseUp += txtNode_MouseUp;
            txtNode.MouseMove += txtNode_MouseMove;
            txtNode.KeyDown += txtNode_KeyDown;
            txtNode.Leave += txtNode_Leave;

            timerTxt = new Timer();
            timerTxt.Interval = 1000;
            timerTxt.Enabled = false;
            timerTxt.Tick += timerTxt_Tick;

            currentTime = DateTime.Now;
            // Use reflection to load the
            // embedded bitmaps for the
            // styles plus and minus icons
            Assembly myAssembly = Assembly.GetAssembly(Type.GetType("JsmCalendar.CalendarView"));
            ////string filename = Application.StartupPath + @"\Image\tv_minus.bmp";
            ////bmpMinus = new Bitmap(filename);  yixun
            ////bmpMinus = new Bitmap(Application.StartupPath + @"\Image\tv_plus.bmp");
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CalendarView));
               //// bmpMinus = ((System.Drawing.Bitmap)(resources.GetObject("tv_minus.bmp")));
        }
 private int GetChildNodeCount(TreeListNode node)
 {
     int rs = 0;
     foreach (TreeListNode n in node.Nodes)
     {
         rs++;
         if (n.IsExpanded)
         {
             rs = rs + GetChildNodeCount(n);
         }
     }
     return rs;
 }