e.Graphics.DrawString("现在的时间是"+dTime.ToString(),new Font("Curior New",18f),new SolidBrush(Color,Black),50f,100f.null);源代码
using System;using System.Drawing;
using System.Windows.Forms;
public class PresentTimeForm : System.Windows.Forms.Form
{
DateTime dTime;
public PresentTimeForm()
{
this.ClientSize = new System.Drawing.Size(500, 200);
this.Text = "what time is it now?";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PresentTimeForm_Paint); }
static void Main() {
Application.Run(new PresentTimeForm());
}
private void PresentTimeForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { dTime = DateTime.Now;
e.Graphics.DrawString("现在的时间是"+dTime.ToString(),new Font("Curior New",18f),new SolidBrush(Color,Black),50f,100f.null);
}
}
using System;using System.Drawing;
using System.Windows.Forms;
public class PresentTimeForm : System.Windows.Forms.Form
{
DateTime dTime;
public PresentTimeForm()
{
this.ClientSize = new System.Drawing.Size(500, 200);
this.Text = "what time is it now?";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PresentTimeForm_Paint); }
static void Main() {
Application.Run(new PresentTimeForm());
}
private void PresentTimeForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { dTime = DateTime.Now;
e.Graphics.DrawString("现在的时间是"+dTime.ToString(),new Font("Curior New",18f),new SolidBrush(Color,Black),50f,100f.null);
}
}
解决方案 »
- 如何给一个现有的TreeView增加节点
- 关于ACCESS中SQL的时间问题
- HttpWebRequest 多线程 同步 异步 的问题
- 用过加密狗的进
- .Net2.0的setup.exe,有什么工具可以监控安装的时候写注册表和复制什么文件到什么目录呢?
- 针对DataGrid控件模板列保存数据的问题!
- 问个简单的按回车键问题
- 如何得出两个日期间 周 的开始日期、结束日期
- 请问能不能.net有没有一个机制能够控制 动态引用的一个外部类(如dll)的操作权限?
- 利用栈技术不采用递归遍历treeview的节点的问题
- 【关于c#ToBase64String加密上传图片】在线等。。。。。。
- 为什么不同电脑返回不同的SQL结果呢?
{
using (Brush bs = new SolidBrush(Color, Black))
{
e.Graphics.DrawString("现在的时间是" + dTime.ToString(), ft, bs, 50f, 100f);
}
}
//或
using (Font ft = new Font("Curior New", 18f))
{
e.Graphics.DrawString("现在的时间是" + dTime.ToString(), ft, Brushes.Black , 50f, 100f);
}你原来的代码100f.null处是语法错误.GDI对象在new出来后,一定要调用Dispose()方法,或使用using块去自动调用Dispose方法.否则你的软件如果常时间运行的话,可能把系统的GDI资源全部耗尽.