国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
C#中pictureBox上如何設(shè)置label透明

C#中pictureBox上如何設(shè)置label透明

 

pictureBox的Paint事件中寫下如下代碼

private void pictureBox1_Paint(object sender, PaintEventArgs e)

        {

            foreach (Control C in this.Controls)

            {

                if (C is Label)

                {

                    Label L = (Label)C;

                   L.Visible = false;

                    e.Graphics.DrawString(L.Text, L.Font, new

          SolidBrush(L.ForeColor), L.Left - pictureBox1.Left, L.Top - pictureBox1.Top);

                }

            }

        }

或者在載入頁面的時(shí)候在LOAD中寫入下面代碼:

pictureBox1.SendToBack();

            label1.BackColor = Color.Transparent;

            label1.Parent = pictureBox1;

            label1.BringToFront();
 

關(guān)鍵點(diǎn)有2點(diǎn):

1、將此控件的背景顏色設(shè)為透明色,

2、將此控件和父控件關(guān)聯(lián),即和PictureBox控件相關(guān)聯(lián)。

范例代碼如下:(關(guān)鍵性代碼已用黑體字表示)

范例功能:當(dāng)鼠標(biāo)在圖片上按下時(shí),顯示“你好”,當(dāng)鼠標(biāo)抬起后,文字自動(dòng)消失。

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 + "\\cc1.bmp";
            lblResult = new Label();                                       
            lblResult.Location = new Point(0,0);
            lblResult.Parent = pbCCD;                                 //將label和picturebox(只是我命名為pbCCD而已)關(guān)聯(lián)!
            lblResult.BackColor = Color.Transparent;     //設(shè)置label的背景色為透明色。

            lblResult.Text = "你好!";
            lblResult.Visible = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pbCCD.Load(filename);
        }

        private void pbCCD_MouseDown(object sender, MouseEventArgs e)
        {
            lblResult.Visible = true;
           
            lblResult.Location = e.Location;
        }

        private void pbCCD_MouseUp(object sender, MouseEventArgs e)
        {
            lblResult.Visible = false;
        }
    }

如何在PictureBox上透明的顯示文字2(利用Graphics技術(shù))
2008-04-14 15:52

利用c#的GDI+技術(shù),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 + "\\cc1.bmp";
        }

        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();
        }
    }
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
V9.1PictureBox控件
C# PictureBox 使用心得
數(shù)字圖像處理 C# 程序代碼實(shí)例
C#生成和識(shí)別二維碼
個(gè)picturebox,一個(gè)放圖片
求助
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服