久久久久久久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 的類)
主站蜘蛛池模板: 911精品美国片911久久久 | 国产高清精品一区二区三区 | 亚洲精品电影网在线观看 | 亚洲欧美一区二区三区视频 | 一区二区影视 | 日本久久综合网 | 精品福利一区二区三区 | 久久高清精品 | 亚洲欧美中文日韩在线v日本 | 久久国产精品免费视频 | 久久久精品一区二区三区 | 午夜精品久久久 | 中文字幕一区二区三区四区五区 | 久久久久久国产免费视网址 | 视频在线亚洲 | 伊色综合久久之综合久久 | 国产99在线 | 欧美 | 久久成人精品视频 | 99精品在线| 久久久精彩视频 | 国产精品成人一区二区三区 | 成人久草| 九久久 | 一区二区三区久久久 | 国产一区二区免费电影 | 国产欧美一区二区精品忘忧草 | 欧美乱操| 久草网免费 | 91黄色片免费看 | 精品一区二区三区在线观看国产 | 毛片一区二区三区 | 亚洲二区视频 | 久久久精品影院 | 久久69精品久久久久久久电影好 | 亚洲一区二区免费 | 欧美日韩精品久久久免费观看 | 亚洲另类春色偷拍在线观看 | 日韩国产欧美视频 | 亚洲二区在线观看 | 久久国产综合 | 午夜精品在线 |