如何在List <drawaction>中StreamWrite画笔的颜色?

时间:2018-05-06 10:26:16

标签: c# winforms list class stream

class DrawAction
{
    public Rectangle Dortgen { get; set; }
    public Brush Firca { get; set; }
    public PointF Koordinat { get; set; }
    public DrawAction(Brush color_, Rectangle rect_ )
    { Dortgen = rect_; Firca = color_; }
    public DrawAction(Brush color_)
    { Firca = color_; }
    public DrawAction (PointF k_)
    { Koordinat = k_; }
}
    List<DrawAction> kare = new List<DrawAction>();
    Brush brush = new SolidBrush(Color.Red);

    private void Panel1_MouseUp(object sender, MouseEventArgs e)
    {
        if (SeciliSekil == "Dikdortgen")
        {
            if (End.Y > Start.Y && End.X > Start.X)
                kare.Add(new DrawAction(brush, new Rectangle(Start.X, Start.Y, End.X - Start.X, End.Y - Start.Y)));
            else if (End.Y < Start.Y && End.X > Start.X)
                kare.Add(new DrawAction(brush, new Rectangle(Start.X, End.Y, End.X - Start.X, Start.Y - End.Y)));
            else if (End.Y > Start.Y && End.X < Start.X)
                kare.Add(new DrawAction(brush, new Rectangle(End.X, Start.Y, Start.X - End.X, End.Y - Start.Y)));
            else if (End.Y < Start.Y && End.X < Start.X)
                kare.Add(new DrawAction(brush, new Rectangle(End.X, End.Y, Start.X - End.X, Start.Y - End.Y)));
        }

    private void SaveButton_Click(object sender, EventArgs e)
    {
        StreamWriter dortgenrenk = File.CreateText("DortgenRenk.txt");
        dortgenrenk.Close();

        StreamWriter DortColor;
        List<string> DortC = new List<string>();
        foreach (DrawAction yazdortC in kare)
            DortC.Add((yazdortC.Firca).ToString());
        foreach (string s in DortC)
        {
            DortColor = File.AppendText("DortgenRenk.txt");
            DortColor.WriteLine(s);
            DortColor.Close();
        }
    }

以下是我的一些代码。我将数据保存在List kare中。我想要到达所有画笔并将它们的颜色写入.txt。我试过这个。

现在节省了一些东西。我打开了.txt。写了“System.Drawing.SolidBrush”。但我需要颜色。

0 个答案:

没有答案