TableLayout 面板 - 边框颜色和偏移

问题描述

我正在开发一个关于建筑立面系统的 C# winform 项目。这个项目使用一个 TableLayoutPanel 控件,所有单元格都有带有边框样式的图片框。

我想在这个闪电区域周围画一条线或边框。 我使用了 cellpaint 事件并实现了绘制。我想给一些偏移量,并且我想改变与图片框相同的绘制颜色(边框样式固定)

这些是代码:

private void DispData_Click(object sender,RoutedEventArgs e)
{
    try
    {
        PlacementInvoicesEntities conn = new PlacementInvoicesEntities();

        List<PermAutomation_Log> TableData = conn.PermAutomation_Log.ToList();
        PermInvoices.ItemsSource = TableData;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

enter image description here

编辑:

使用颜色拾取应用程序,可以获取颜色的属性(Argb)。所以我用想要的颜色定义了新的笔

private void tlp1_CellPaint(object sender,TableLayoutCellPaintEventArgs e)
        {
            if (confirmedView)
            {
              Pen borderPen = new Pen(Color.FromArgb(100,100,100),2);
                if(e.Column== cellStartColumnIndex|| e.Column == cellStartColumnIndex+1 || e.Column == cellStartColumnIndex + 2)
                {
                    if(e.Row == cellStartRowIndex)
                    {
                        var topLeft = e.CellBounds.Location;
                        var topRight = new Point(e.CellBounds.Right,e.CellBounds.Top);
                        e.Graphics.DrawLine(borderPen,topLeft,topRight);
                    }
                }
                if (e.Row == cellStartRowIndex || e.Row == cellStartRowIndex + 1)
                {
                    if (e.Column == cellStartColumnIndex|| e.Column == cellStartColumnIndex+3)
                    {
                        var topLeft = e.CellBounds.Location;
                        var topRight = new Point(e.CellBounds.Left,e.CellBounds.Bottom);
                        e.Graphics.DrawLine(borderPen,topRight);
                      }
                 }
          }
        }

对于边框偏移,@Jimi 建议我使用填充属性。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)