您的位置:首页 > 其它

如何在PictureBox上透明的显示文字

2015-01-22 20:18 1011 查看
利用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();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: