zoukankan      html  css  js  c++  java
  • C# vs2017 winForm 未解之谜(一)关于重绘tableLayoutPanel单元格边框后的问题

    1.用label填充tableLayoutPanel1单元格,label的属性设置为:

    anchor:Top, Bottom, Left, Right;

    Dock:Fill;

    margin:1,1,1,1

    Rowspan:2;//根据需要

    TextAline:MiddleCenter;

    其他属性默认

    tableLayoutPanel1的属性默认

    得到的结果为:

    为了显示表格边框线,在tableLayoutPanel1_CellPaint事件中绘制单元格边框:

            private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
            { //绘制单元格边框
                Pen cpen = new Pen(Color.Black);
                cpen.Width = 1F;
                Rectangle rectangle = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.X + this.Width, e.CellBounds.Y + this.Height);
                e.Graphics.DrawRectangle(cpen,rectangle);
            }

    得到的结果为(tableLayoutPanel1的底边和右边边框线不显示,这是问题一):

    补救办法一,在tableLayoutPanel1的四个边框处绘制矩形:

            private void SplitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
            {//绘制表格边框
                Pen tpen = new Pen(Color.Black);
                tpen.Width = 1F;
                int x = tableLayoutPanel1.Bounds.X;
                int y = tableLayoutPanel1.Bounds.Y;
                int width = tableLayoutPanel1.Width;
                int height = tableLayoutPanel1.Height;
                //绘制矩形
                Rectangle rectangle = new Rectangle(x, y, x + width, y + height);
                e.Graphics.DrawRectangle(tpen, rectangle);
            }

    得到的结果为:tableLayoutPanel1右边框和下边框和单元格之间有缝隙,这是问题二(tableLayoutPanel1放在SplitContainer1_Panel1内):

    补救办法二,单独绘制tableLayoutPanel1的下边框和右边框:

            private void SplitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
            {//绘制表格右、下边框
                Pen tpen = new Pen(Color.Black);
                tpen.Width = 1F;
                int x = tableLayoutPanel1.Bounds.X;
                int y = tableLayoutPanel1.Bounds.Y;
                int width = tableLayoutPanel1.Width;
                int height = tableLayoutPanel1.Height;
                //绘制矩形
                //Rectangle rectangle = new Rectangle(x, y, x + width, y + height);
                //e.Graphics.DrawRectangle(tpen, rectangle);
                //绘制底边
                e.Graphics.DrawLine(tpen, x, y + height, x+width, y + height);
                //绘制右边
                e.Graphics.DrawLine(tpen, x + width, y, x + width, y + height);
            }        

    得到结果为:

    求问题一和问题二出现的原因?

  • 相关阅读:
    批量插入测试脚本
    Show Profile分析sql语句的资源消耗
    慢查询日志
    ORDER BY优化
    Join查询
    Explain(执行计划)分析
    索引
    MySQL中的DML(数据操作语言)和DQL(数据查询语言)
    MySQL中的DDL(数据定义语言)和DCL(数据控制语言)
    MySQL架构体系介绍
  • 原文地址:https://www.cnblogs.com/nb08611033/p/8901406.html
Copyright © 2011-2022 走看看