我有一个应用程序,我正在写我必须在预先定义的标签工作表上放置街道地址的地方。该标签页有3列10行。我有一个能够正确创建标签的循环,但是有一个要求允许用户选择纸张上的标签来开始。我原以为这将是一个简单的数学矩阵方程,但我无法想出或找到解决方案。给定网格中的位置,它是什么行和列
下面是一个例子:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
鉴于上面的矩阵,可以说用户决定开始#6。我需要能够告诉我的循环从该位置开始:col:1 row: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();
}
你能不能拿数字鸿沟是由数量列来获取行并使用余数来移动到正确列的位置?希望我解释得那么好..... – Sorceri
对不起,Sorceri,也许我误解你的意思,但它与数字9一起工作,但让我们取数字4.我的矩阵有3列10行(或30标签可能),如果我将30除以4,我会得到7.5。列和行分别为4 1和2,所以这不起作用。 – gcoleman0828
你不会按行分割它,而是按行分割以获得这样的行,所以4/3是1行,其余1行是1列。我正在解释你接受的答案,只是没有做得很好;) – Sorceri