如何在PictureBox上透明的显示文字2(利用Graphics技术)

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

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

范例代码如下:

 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.Windows.Forms;
 8
 9namespace CCDTest
10{
11    public partial class Form1 : Form
12    {
13        string filename;
14        //Label lblResult;
15        public Form1()
16        {
17            InitializeComponent();
18            filename = Application.StartupPath + "\\cc1.bmp";
19        }

20
21        private void Form1_Load(object sender, EventArgs e)
22        {
23            pbCCD.Load(filename);
24        }

25
26        private void pbCCD_MouseDown(object sender, MouseEventArgs e)
27        {
28            PointF pf = e.Location;
29
30            using (Graphics g = pbCCD.CreateGraphics())
31            {
32                Console.WriteLine("Beg MyDraw.");
33                Font f = new Font("Arial"12);
34                g.DrawString("Hello!", f, Brushes.Violet, pf);
35                Console.WriteLine("End MyDraw..");
36            }

37        }

38
39        private void pbCCD_MouseUp(object sender, MouseEventArgs e)
40        {
41            pbCCD.Invalidate();
42        }

43    }

44}

45

posted on 2008-05-20 12:11  Love↗钰珂  阅读(1768)  评论(0)    收藏  举报

导航