Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中使用drawString更新日期#_C#_.net_Winforms - Fatal编程技术网

C# 如何在C中使用drawString更新日期#

C# 如何在C中使用drawString更新日期#,c#,.net,winforms,C#,.net,Winforms,我正在使用WindowsForms,我绘制图形,希望在程序的每个步骤中显示每个日期。例如,图形每天都在变化。 因此,我的图形是好的,但我不能改变我的日期短信。 我用的是AddDays,但我不能把它放在循环中 Font drawFont = new Font("Arial", 12); SolidBrush drawBrush = new SolidBrush(Color.Black); DateTime dt = new DateTime(2015, 02, 02); // Or whatev

我正在使用WindowsForms,我绘制图形,希望在程序的每个步骤中显示每个日期。例如,图形每天都在变化。 因此,我的图形是好的,但我不能改变我的日期短信。 我用的是AddDays,但我不能把它放在循环中

Font drawFont = new Font("Arial", 12);
SolidBrush drawBrush = new SolidBrush(Color.Black);

DateTime dt = new DateTime(2015, 02, 02); // Or whatever
DateTime dt2 = dt.AddDays(1);
string sqqq = dt2.ToString("dd/MM/yyyy");

Graphics g4 = pictureBox1.CreateGraphics();
g4.DrawString(sqqq, drawFont, drawBrush, lol2, kek2);
我将代码更改为:

    Graphics g4 = pictureBox1.CreateGraphics();
    DateTime dt = new DateTime(2015, 02, 02); // Or whatever
    for (int i = 0; i < n; i++)
    {
        DateTime dt2 = dt.AddDays(1);

        string sqqq = dt2.ToString("dd/MM/yyyy");
        g4.DrawString(sqqq, drawFont, drawBrush, lol2, kek2);
        dt = dt2;
    }
Graphics g4=pictureBox1.CreateGraphics();
DateTime dt=新的日期时间(2015,02,02);//或者别的什么
对于(int i=0;i

它会更新日期,但现在在每一步中,我以前的日期都会覆盖新的日期。它相互重叠。如何删除以前的文本图形?

停止使用CreateGraphics(),开始使用Paint事件。调用其Invalidate()方法以获得重绘,通常是使用计时器的勾号事件。那么,除了非持久性图形和泄漏资源(字体和笔刷)之外,问题出在哪里?日期字符串??知道什么时候画画吗?(timer.Tick)我的程序的每一步都有什么?所以我的代码中有“求解”按钮,比如迭代。我想在每次按下“解决”按钮时更新我的数据,以便在单击按钮时添加pictureBox1.Invalidate()。当然,在pictureBox1.Paint代码中使用e.Graphics对象绘制字符串!在Winforms中,最好在图像顶部用透明背景将Label控件分层,然后更新标签。停止使用CreateGraphics(),开始使用Paint事件。调用其Invalidate()方法以获得重绘,通常是使用计时器的勾号事件。那么,除了非持久性图形和泄漏资源(字体和笔刷)之外,问题出在哪里?日期字符串??知道什么时候画画吗?(timer.Tick)我的程序的每一步都有什么?所以我的代码中有“求解”按钮,比如迭代。我想在每次按下“解决”按钮时更新我的数据,以便在单击按钮时添加pictureBox1.Invalidate()。当然,在pictureBox1.Paint代码中使用e.Graphics对象绘制字符串!在Winforms中,最好将标签控件分层,并在图像顶部添加透明背景,然后更新标签。