我正在编写一个应用程序,需要将街道地址放在预定义的标签纸上。该标签纸有3列和10行。我已经正确创建了生成标签的循环,但是要求允许用户选择从哪个标签开始。我原以为这是一个简单的数学矩阵方程,但我无法想出或找到解决方案。
以下是示例:
以下是示例:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
假设给定上面的矩阵,用户决定从#6开始。我需要能够告诉我的循环从该位置开始:列:1行:2。
如果有帮助的话,我拥有的循环看起来像这样,但我认为这归结于我没有考虑的数学方程:
for (var yCounter = 0; yCounter < _labelSettings.LabelPerColumn; yCounter++)
{
for (var xCounter = 0; xCounter < _labelSettings.ColumnsPerPage; xCounter++)
{
foreach (var table in customNugget.PdfTables)
{
table.YPosition = SheetSettings.PageHeight -
(verticalOffset + yCounter * ((verticalSize + verticalOffset)));
table.XPosition = horizontalOffset + xCounter * ((horizontalSize + horizontalOffset));
}
}
}
编辑
private static int _cellsPerRow = 3;
private static int _startIndex;
static void Main(string[] args)
{
string userInput = Console.ReadLine();
_startIndex = int.Parse(userInput);
int startY = _startIndex / _cellsPerRow;
int startX = (_startIndex - 1) % _cellsPerRow;
Console.WriteLine(string.Format("The index you chose lives in the following matrix location:\n Row: {0} Column: {1}", startY, startX));
Console.WriteLine("Press any key to continue...");
Console.Read();
}