Visual Studio 2008 SP1 C# Windows 应用程序
我正在直接在主窗体上书写和绘图,并且在重新绘制屏幕时遇到问题。在程序启动时,屏幕正确绘制。在 3-4 秒内再出现两条绘制消息(屏幕上没有动作或动作),并且使用屏幕坐标(我认为)而不是客户端坐标绘制屏幕。原始字符串不会被删除。
为了将问题简化为最简单的形式,我启动了一个新的 C# windows 应用程序。除了在主窗体上绘制一个字符串之外,它什么也不做。(见下面的代码片段)如果你启动程序,字符串会出现,然后第二个字符串会出现在上面和左边。如果您重新启动程序并将窗体移到屏幕的左上角,两个字符串将几乎重合。这就是为什么我认为第二次绘画使用屏幕坐标的原因。
这是代码 - 提前感谢您提供的任何帮助。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Junk
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs eventArgs)
{
using (Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic))
{
eventArgs.Graphics.TranslateTransform(0, 0);
Point p;
eventArgs.Graphics.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, 200, 200);
} //myFont is automatically disposed here, even if an exception was thrown
}
}
}