如何在picturebox上写入文字

chenjiecao123 chenjiecao123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好,以下是一段代码,可是没有实现,我的理解是,一开始运行程序后就会运行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");
}
}
}
...全文
评论 8
收藏 已收藏
分享
返回顶部
chenjiecao123
C# 111,128 成员 642,536 内容