Hey Community,
ich habe mal wieder eine Art Problem. Ich code momentan meinen SudokuSolver neu, und es geht vorest darum ein schönes Control zu haben. Das Problem dabei sind die Zahlen darin: Bekanntlicher Weise hat ja ein SudokuFeld 81 Felder, und ich kenne die Koordiaten der Mitte (die sind auch richtig!). Wenn ich jetzt mit Tahoma
Number + Rectangle
ich habe mal wieder eine Art Problem. Ich code momentan meinen SudokuSolver neu, und es geht vorest darum ein schönes Control zu haben. Das Problem dabei sind die Zahlen darin: Bekanntlicher Weise hat ja ein SudokuFeld 81 Felder, und ich kenne die Koordiaten der Mitte (die sind auch richtig!). Wenn ich jetzt mit Tahoma
new Font("Calibri", 13, FontStyle.Bold)
die Zahlen zeichne, sind sie nicht 100%-ig zentral, ich müsste 1px Offset in beide Richtungen hinzufügen. Liegt das an der Schriftart oder an meinem Code ?:
Das erste Bild ist das Resultat von dem Code, das zweite ist dsa gleiche nur halt in Zeile 13 mit
new PointF(x+1, y+1)
. Das Recteck beschreibt nur die Größe des Chars (siehe Code).C#-Quellcode
- List<int> centers = GetListOfCenters();
- int i = 1;
- int j = 1;
- foreach (int x in centers)
- {
- foreach (int y in centers)
- {
- string txt = Sudoku.GetCell(i, j).ToString();
- StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
- //Normal
- e.Graphics.DrawString(txt, this.Font, new SolidBrush(this.ForeColor), new PointF(x, y), sf);
- //Rectangle
- SizeF fontsize = e.Graphics.MeasureString(txt, this.Font);
- e.Graphics.DrawRectangle(new Pen(Color.Red, 1), x - fontsize.Width / 2, y - fontsize.Height / 2, fontsize.Width, fontsize.Height);
- j++;
- }
- i++;
- j = 1;
- }
»There's no need to "teach" atheism. It's the natural result of education without indoctrination.« — Ricky Gervais