简体   繁体   English

在单元格组周围绘制刻度线边框(TableLayoutPanel C#)

[英]Draw tick border around group of cells (TableLayoutPanel C#)

I'm making a sudoku field in a windows form application (c#) 我在Windows窗体应用程序(C#)中创建数独字段

I've used a TableLayout to make my boxes to put labels in for the numbers displayed in the sudoku, now I need a thick border around every group of 3x3 cells (like a sudoku)... 我已经使用TableLayout制作框来为数独中显示的数字添加标签,现在我需要在每组3x3单元格(如数独)周围加粗边框...

I'm trying with the CellPaint object but I can't set a border around a group of borders... 我正在尝试使用CellPaint对象,但无法在一组边界周围设置边界...

您可以尝试将面板添加到左上角的单元格,并将其RowSpan和ColSpan设置为3。之后,您可以在其上绘制任何边框。

Step 1 第1步

  • Create a UserControl 创建一个用户控件
  • Set Background to Black, Margin to 0, 0, 0, 0 and Padding to 3, 3, 3, 3 将背景设置为黑色,边距设置为0、0、0、0,填充设置为3、3、3、3
  • Add a TableLayoutControl with 3 Row & 3 Cells (33% each) 添加具有3行和3单元格(每个33%)的TableLayoutControl
  • Set TableLayoutControl Dock to Fill and BackColor to Black 将TableLayoutControl Dock设置为Fill,将BackColor设置为Black
  • Add a Label to each cell, Margin 1, BackColor White 向每个单元格,边距1,背景色白色添加标签

Step 2 第2步

  • Create another UserControl with 3x3 cells (33% each) 使用3x3单元格(每个33%)创建另一个UserControl
  • add an instance of your first UserControl to every single cell 将第一个UserControl的实例添加到每个单元格
  • now you have double borders where two controls are besides each other but you can easily adjust this by setting the padding for the indiviual usercontrols. 现在您有了双边框,其中两个控件彼此相邻,但是您可以通过为单个用户控件设置填充来轻松调整此边框。 I would suggest you leave the one in the middle with 3, 3, 3, 3 and modify the outer controls 我建议您将中间的3、3、3、3留在中间,然后修改外部控件

Here is a sample, left is UserControl1, right is UserControl2 with 9x UserControl1 这是一个示例,左为UserControl1,右为UserControl2,带有9x UserControl1
I used padding 4 on the outer sides and padding 2 on the inner sides. 我在外侧使用填充4,在内侧使用填充2。

样品

we had to change our code for making the labels and are doing it this way... 我们必须更改用于制作标签的代码,并以此方式进行操作...

const int spacing = 30;  //ruimte tussen kotjes
                    int aantal = (int)nudColsPerBlock.Value * (int)nudRowsPerBlock.Value; //totaal aantal kotjes per rij/kolom
                    Label[][] SudokuRaster = new Label[aantal][];
                    for (int x = 0; x

But I still need thick borders between some of the labels, any tips? 但是我仍然需要一些标签之间的粗边框,有什么提示吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM