picturebox 怎样显示文字

picturebox 怎样显示文字,第1张

利用c#的GDI+技术,PictureBox.CreateGraphics()绘图,利用g.DrawString写文字

利用this.Invalidate()刷新Form窗体,或者利用PictureBox.Invalidate()刷新PictureBox.。

代码如下:

using System

using System.Collections.Generic

using System.ComponentModel

using System.Data

using System.Drawing

using System.Text

using System.Windows.Forms

namespace CCDTest

{

public partial class Form1 : Form

{

string filename

//Label lblResult

public Form1()

{

InitializeComponent()

filename = Application.StartupPath + ""

}

private void Form1_Load(object sender, EventArgs e)

{

pbCCD.Load(filename)

}

private void pbCCD_MouseDown(object sender, MouseEventArgs e)

{

PointF pf = e.Location

using (Graphics g = pbCCD.CreateGraphics())

{

Console.WriteLine("Beg MyDraw....")

Font f = new Font("Arial", 12)

g.DrawString("Hello!", f, Brushes.Violet, pf)

Console.WriteLine("End MyDraw.....")

}

}

private void pbCCD_MouseUp(object sender, MouseEventArgs e)

{

pbCCD.Invalidate()

}

}

}

 Graphics a = Graphics.FromImage(this.pictureBox1.Image)

//改为:

Graphics a = pictureBox1.CreateGraphics()

去掉

a.Dispose()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11714204.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存