如何在picturebox上写入文字
大家好,以下是一段代码,可是没有实现,我的理解是,一开始运行程序后就会运行onpaint函数,我用messagebox测试是运行的,但是为什么并没有画出来,而我拖动窗口的时候却有出现文字,请大侠们帮忙解释下原理啊。
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void Paintp();
public event Paintp p;
private void Form1_Load(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)//绿色
{
MessageBox.Show("OnPaint");
PointF pf = new PointF(200, 200);
using (Graphics g = pictureBox1.CreateGraphics())
{
Font f = new Font("Arial", 12);
g.DrawString("Hello!", f, Brushes.Green, pf);
}
MessageBox.Show("OnPaint2");
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void Paintp();
public event Paintp p;
private void Form1_Load(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)//绿色
{
MessageBox.Show("OnPaint");
PointF pf = new PointF(200, 200);
using (Graphics g = pictureBox1.CreateGraphics())
{
Font f = new Font("Arial", 12);
g.DrawString("Hello!", f, Brushes.Green, pf);
}
MessageBox.Show("OnPaint2");
}
}
}
...全文


