久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

對 PictureBox 的透明控制

Transparent control over PictureBox(對 PictureBox 的透明控制)
本文介紹了對 PictureBox 的透明控制的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在我的 C# 表單中,我有一個(gè)在下載事件中顯示下載百分比的標(biāo)簽:

In my C# Form I have a Label that displays a download percentage in the download event:

  this.lblprg.Text = overallpercent.ToString("#0") + "%";

Label 控件的 BackColor 屬性設(shè)置為透明,我希望它顯示在 PictureBox 上.但這似乎無法正常工作,我看到灰色背景,在圖片框頂部看起來不透明.我該如何解決這個(gè)問題?

The Label control's BackColor property is set to be transparent and I want it to be displayed over a PictureBox. But that doesn't appear to work correctly, I see a gray background, it doesn't look transparent on top of the picture box. How can I fix this?

推薦答案

Label控件很好的支持透明.只是設(shè)計(jì)師不會(huì)讓你正確放置標(biāo)簽.PictureBox 控件不是容器控件,因此 Form 成為標(biāo)簽的父級.所以你會(huì)看到表單的背景.

The Label control supports transparency well. It is just that the designer won't let you place the label correctly. The PictureBox control is not a container control so the Form becomes the parent of the label. So you see the form's background.

通過向表單構(gòu)造函數(shù)添加一些代碼很容易解決.您需要更改標(biāo)簽的 Parent 屬性并重新計(jì)算它的 Location,因?yàn)樗F(xiàn)在是相對于圖片框而不是表單.像這樣:

It is easy to fix by adding a bit of code to the form constructor. You'll need to change the label's Parent property and recalculate it's Location since it is now relative to the picture box instead of the form. Like this:

    public Form1() {
        InitializeComponent();
        var pos = this.PointToScreen(label1.Location);
        pos = pictureBox1.PointToClient(pos);
        label1.Parent = pictureBox1;
        label1.Location = pos;
        label1.BackColor = Color.Transparent;
    }

在運(yùn)行時(shí)看起來像這樣:

Looks like this at runtime:

另一種方法是解決設(shè)計(jì)時(shí)問題.那只需要一個(gè)屬性.添加對 System.Design 的引用并向您的項(xiàng)目添加一個(gè)類,粘貼以下代碼:

Another approach is to solve the design-time problem. That just takes an attribute. Add a reference to System.Design and add a class to your project, paste this code:

using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;    // Add reference to System.Design

[Designer(typeof(ParentControlDesigner))]
class PictureContainer : PictureBox {}

這篇關(guān)于對 PictureBox 的透明控制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執(zhí)行 Excel NORMINV 函數(shù)的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權(quán)列表中選擇 x 個(gè)隨機(jī)元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創(chuàng)建時(shí)間表的摘要描述)
C# Normal Random Number(C# 普通隨機(jī)數(shù))
Standard deviation of generic list?(通用列表的標(biāo)準(zhǔn)偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創(chuàng)建一個(gè) IAwaitable 的類)
主站蜘蛛池模板: 欧美一区二区三区电影 | 欧美一区二区三区在线观看 | 国产91亚洲精品一区二区三区 | 国产视频1区 | 综合中文字幕 | 精品自拍视频在线观看 | 国产精品久久毛片av大全日韩 | 国产精品免费一区二区三区四区 | 日韩成人 | 99成人| 日韩中文字幕 | 免费av直接看 | 奇米四色在线观看 | 国产专区免费 | 久久乐国产精品 | 国产乱码久久久久久 | 久久精品99久久 | 夜夜爽99久久国产综合精品女不卡 | 欧美日韩视频在线播放 | 午夜一级做a爰片久久毛片 精品综合 | 龙珠z国语版在线观看 | 精品国产乱码久久久久久闺蜜 | 亚洲福利视频一区二区 | 一级黄色片毛片 | 狠狠干网站 | 草草草影院 | 91久久综合亚洲鲁鲁五月天 | 一区二区三区在线免费观看 | 欧美久久久久 | 激情五月激情综合网 | 午夜寂寞福利视频 | 国产综合久久 | 欧洲一区二区视频 | 超碰97免费在线 | 色播久久久 | 色婷婷国产精品综合在线观看 | 91在线看片 | 国产一级特黄aaa大片评分 | 中文字幕日韩一区二区 | 五月天天色 | 农村黄性色生活片 |