代码没有问题,是坐标位置超出了pictureBox的范围 public delegate void Paintp();
public event Paintp p;
protected override void OnPaint(PaintEventArgs e)//绿色
{
PointF pf = new PointF(0, 0); //注意文字显示的坐标位置
using (Graphics g = pictureBox1.CreateGraphics())
{
Font f = new Font("Arial", 12);
g.DrawString("Hello!", f, Brushes.Green, pf);
}
}
public event Paintp p;
protected override void OnPaint(PaintEventArgs e)//绿色
{
PointF pf = new PointF(0, 0); //注意文字显示的坐标位置
using (Graphics g = pictureBox1.CreateGraphics())
{
Font f = new Font("Arial", 12);
g.DrawString("Hello!", f, Brushes.Green, pf);
}
}
解决方案 »
- 多线程实现timer控件刷新显示时间 如何做?
- datagridview 小问题
- Excel导入datatable,再导入数据库,导入数据库时还要判断,有些记录是数据库已经有的不能导入,谁做过?有代码最好
- 很基本的显示,却半天出不来,,,,
- 引用类型的单元测试
- winform 中的DataGrid 可以添加checkbox吗?在线等,急用
- VS2005中TableLayoutPanel的经典问题,希望大家帮帮忙,贡献出我最后90分
- 请问 CoInitializeEx 和 CoUninitialize 如何声明?(多线程调用COM对象)
- 怎么把这段vb sript写的wmi脚本改写成c#语法的程序?
- 大家看CSDN的2003年4月所登出的 SilderWinder的信息了吗?Borland公司的C#编译器,同时还要捆绑Together for C#。你会转向使用SilderWind
- 求解:SQL连接超时,什么原因
- ?TCP client无应答时程序明显变慢,有什么办法可以加速,谢谢
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e) //用按钮在pictureBox1内写字
{
Graphics g = pictureBox1.CreateGraphics();
Brush ft=new SolidBrush(Color.FromArgb(100, 200, 30));
Point p=new Point (0,100);
g.DrawString("在这里写字!",new Font ("宋体",20),ft,p );
} private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush ft = new SolidBrush(Color.FromArgb(100, 200, 30));
Point p = new Point(45, 45);
g.DrawString("这是pictureBox1_Paint写字!", new Font("宋体", 20), ft, p);
} private void button2_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Brush ft = new SolidBrush(Color.FromArgb(100, 200, 30));
Point p = new Point(0, 0);
g.DrawString("这是在窗体上里写字!", new Font("宋体", 20), ft, p);
}
}
}
不要忘记调用base.onPaint(e);附:修改你的代码protected override void OnPaint(PaintEventArgs e)
{
PointF pf = new PointF(200, 200);
Font f = new Font("Arial", 12);
e.Graphics.DrawString("Hello!", f, Brushes.Green, pf);
base.OnPaint(e);
}
var _BSolid = new SolidBrush(Color.Black);
_Graphics.DrawString("欲输出内容", this.Font, _BSolid ,ClientSize.Width - 60, 20);
_BSolid.Dispose();
}
// 做好释放优化工作,别想到现在电脑内存大了硬件配置高了
// 软件是要求越来越快,而不是搞得越来越慢,除非你愿意写垃圾代码