c#显示文字问题–vs2015

使用public void DrawString(string s, Font font, Brush brush, float x, float y);函数

1.新建一个窗体,拖入一个pictureox

1.c#显示文字问题–vs2015
也可以不使用picturebox也行

2.由于绘制文本需要在主窗体初始化之后才能进行操作,所以需要一个延时函数,这里使用定时器来达到延时的目的(不然不能够绘制出文本,调试了小半天才知道)

1.c#显示文字问题–vs2015

定时器定时时间设置和使能定时器

1.c#显示文字问题–vs2015

3.代码

自定义一个函数,用来实现绘制文本操作

public void Str_Vision()
{
string str = “Hello C#!”; //定义绘制的字符串
Font myFont = new Font(“华文行楷”, 20); //创建Font对象
SolidBrush myBrush = new SolidBrush(Color.DarkOrange); //创建画刷对象
Graphics g = this.pictureBox1 . CreateGraphics();
g.DrawString(str, myFont, myBrush, 100, 100); //绘制
}

双击定时器,在定时器里面添加调用自定义的函数

1.c#显示文字问题–vs2015

这里当变量为2时,就能绘制出文字了

1.c#显示文字问题–vs2015

可以给自己的图片添加自己想要的文字啦!

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-01-20
  • 2021-12-24
  • 2021-11-14
  • 2021-07-04
猜你喜欢
  • 2021-09-05
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-12-29
相关资源
相似解决方案