예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            VirtualHeight = 0;
            VirtualWidth  = 0;
            Graphics g = e.Graphics;

            //绘制边框
            if (borderStyle == BorderStyle.FixedSingle)
            {
                Pen     pen   = new Pen(Color.FromArgb(100, 100, 100));
                Point[] point = new Point[4];
                point[0] = new Point(0, 0);
                point[1] = new Point(Width - 1, 0);
                point[2] = new Point(Width - 1, Height - 1);
                point[3] = new Point(0, Height - 1);
                g.DrawPolygon(pen, point);//
            }

            g.TranslateTransform(-listHScroll.Value, 0); //根据滚动条的值设置坐标偏移
            g.TranslateTransform(0, -chatVScroll.Value); //根据滚动条的值设置坐标偏移
            DrawColumn(g);
            g.ResetTransform();                          //重置坐标系
            chatVScroll.VirtualHeight = VirtualHeight;   //绘制完成计算虚拟高度决定是否绘制滚动条
            if (chatVScroll.Visible)                     //是否绘制滚动条
            {
                chatVScroll.ReDrawScroll(g);
            }

            listHScroll.VirtualWidth = VirtualWidth;
            if (listHScroll.Visible)
            {
                listHScroll.ReDrawScroll(g);
            }
        }
예제 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            VirtualHeight = 0;

            _rows.Clear();

            e.Graphics.TranslateTransform(-_hScroll.Value, 0);        //根据滚动条的值设置坐标偏移

            DrawColumn(e.Graphics);

            e.Graphics.TranslateTransform(0, -_vScroll.Value);        //根据滚动条的值设置坐标偏移



            if (DataSource != null)
            {
                e.Graphics.TranslateClip(0, ColumnHeight);//平移 绕过 标题

                using (SolidBrush solidBrush = new SolidBrush(this.ForeColor))
                {
                    Pen    pen   = new Pen(BorderColor);
                    string value = string.Empty;
                    float  y     = ColumnHeight;
                    VirtualHeight = ColumnHeight;
                    int i = 0;
                    foreach (var item in DataSource)
                    {
                        DrawRow(e.Graphics, solidBrush, pen, y, item);
                        RectangleF rectangle = new RectangleF(0, y, (this.Width > VirtualWidth) ? VirtualWidth : this.VirtualWidth, RowHeight);
                        _rows.Add(rectangle);

                        y += RowHeight;
                        e.Graphics.DrawLine(pen, 0, y, (this.Width > VirtualWidth) ? VirtualWidth : this.VirtualWidth, y);
                        VirtualHeight += RowHeight;

                        if (SelectionIndex == i)
                        {
                            solidBrush.Color = SelectionColor;
                            e.Graphics.FillRectangle(solidBrush, rectangle);
                        }
                        else if (m_MouseMoveIndex == i)
                        {
                            solidBrush.Color = MouseMoveColor;
                            e.Graphics.FillRectangle(solidBrush, rectangle);
                        }
                        i++;
                    }
                }
                e.Graphics.TranslateClip(0, -ColumnHeight);
            }

            if (m_DragRowOrColumn == 0)
            {
                if (m_MousePreview != null)
                {
                    e.Graphics.DrawImage(m_MousePreview, m_MouseMovePos.X - m_MouseDownOffset.X, m_MouseMovePos.Y - m_MouseDownOffset.Y);
                }
                //绘制预插入的位置
                if (!m_Prepare.IsEmpty)
                {
                    e.Graphics.DrawRectangle(Pens.Black, m_Prepare.X - 0.5f, m_Prepare.Y, m_Prepare.Width + 0.5f, m_Prepare.Height);
                    e.Graphics.FillRectangle(Brushes.White, m_Prepare);
                }
            }
            e.Graphics.ResetTransform();             //重置坐标系

            _vScroll.VirtualHeight = VirtualHeight;  //绘制完成计算虚拟高度决定是否绘制滚动条
            if (_MouseVisible && _vScroll.Visible)   //是否绘制滚动条
            {
                _vScroll.ReDrawScroll(e.Graphics);
            }

            _hScroll.VirtualWidth = VirtualWidth;
            if (_MouseVisible && _hScroll.Visible)
            {
                _hScroll.ReDrawScroll(e.Graphics);
            }


            if (m_DragRowOrColumn == 1)
            {
                if (m_MousePreview != null)
                {
                    e.Graphics.DrawImage(m_MousePreview, m_MouseMovePos.X - m_MouseDownOffset.X, m_MouseMovePos.Y - m_MouseDownOffset.Y);
                }
                //绘制预插入的位置
                if (!m_Prepare.IsEmpty)
                {
                    e.Graphics.DrawRectangle(Pens.Black, m_Prepare.X - 0.5f, m_Prepare.Y, m_Prepare.Width + 0.5f, m_Prepare.Height);
                    e.Graphics.FillRectangle(Brushes.White, m_Prepare);
                }
            }
        }