如何在PictureBox上透明的显示文字1(利用控件技术)

关键点有2点:

1、将此控件的背景颜色设为透明色,

2、将此控件和父控件关联,即和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            lblResult = new Label();
20            lblResult.Location = new Point(0,0);
21            lblResult.Parent = pbCCD;
22            lblResult.BackColor =
 Color.Transparent;
23            lblResult.Text = "你好!";
24            lblResult.Visible = false;
25        }

26
27        private void Form1_Load(object sender, EventArgs e)
28        {
29            pbCCD.Load(filename);
30        }

31
32        private void pbCCD_MouseDown(object sender, MouseEventArgs e)
33        {
34            lblResult.Visible = true;
35            
36            lblResult.Location = e.Location;
37        }

38
39        private void pbCCD_MouseUp(object sender, MouseEventArgs e)
40        {
41            lblResult.Visible = false;
42        }

43    }

44}

45

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

导航