-1

ここで、特定の座標で文字列を出力するプログラムを作成する必要があります。したがって、文字列の位置には 2 つの変数が必要であり、文字列には文字列変数が 1 つ必要であることはわかっていますが、続行する方法がわかりません。何か案は?

編集これはどこまで来たかです:

class ColoredText
{
    public int x, y; // koordinaterna
    public string hello;
    ConsoleColor färg;

    public ColoredText(int x, int y, string Position)
    {

    }
}
4

4 に答える 4

0

これを試してください: http://msdn.microsoft.com/en-us/library/76c5db29.aspx

public void DrawStringPointF(PaintEventArgs e)
{

    // Create string to draw.
    String drawString = "Sample Text";

    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);

    // Create point for upper-left corner of drawing.
    PointF drawPoint = new PointF(150.0F, 150.0F);

    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
于 2013-02-09T11:51:01.867 に答える
0

FORM の特定の座標に文字列を出力することについて話している場合は、次のようにすることができます...

新しいラベルを作成してフォームに配置し、次のようにします...

次のようにして、ラベルの座標を設定できます。

        int xCoordinate = 0;
        int yCoordinate = 0;
        string labelText = "Enter your text here";

        label1.Location = new Point(xCoordinate, yCoordinate);
        label1.Text = labelText;
于 2013-02-09T11:51:22.493 に答える
0

これに基づい

class ColoredText
{
  public int x, y; // koordinaterna
  public string hello;
  ConsoleColor farg;  // removed the utf-8 char

    public ColoredText(int x, int y, string Position)
    {
       Console.ForegroundColor = farg;
       Console.SetCursorPostion(x,y);
       Console.Write(Position);
       Console.ResetColor();
    }
}
于 2013-02-09T11:54:57.193 に答える
0

C# とタグ付けされています。だから私は私が知っていることで行きます。WPF では、Canvas または Grid を使用したい場合があります。
Grid を使用して、子要素のマージンを設定します。
Canvas では、Top プロパティと Left プロパティを設定します。

// In XAML
<Grid>
    <TextBlock Name="TB"/>
</Grid>

// In code-behind:
Point p = new Point(x, y);
TB.Margin = new Thickness(p.x, p.y, 0, 0);
TB.Text = "Lorem ipsum";
于 2013-02-09T12:04:26.593 に答える