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

對 PictureBox 的透明控制

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

問題描述

在我的 C# 表單中,我有一個在下載事件中顯示下載百分比的標(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 上.但這似乎無法正常工作,我看到灰色背景,在圖片框頂部看起來不透明.我該如何解決這個問題?

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è)計師不會讓你正確放置標(biāo)簽.PictureBox 控件不是容器控件,因此 Form 成為標(biāo)簽的父級.所以你會看到表單的背景.

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 屬性并重新計算它的 Location,因為它現(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;
    }

在運行時看起來像這樣:

Looks like this at runtime:

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

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 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創(chuàng)建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數(shù))
Standard deviation of generic list?(通用列表的標(biāo)準(zhǔn)偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創(chuàng)建一個 IAwaitable 的類)
主站蜘蛛池模板: 欧美日韩一区二区三区视频 | 美国一级黄色片 | 精品国产乱码久久久久久闺蜜 | 午夜精品一区二区三区免费视频 | 特级黄色毛片 | 黄色毛片视频 | 日韩视频一区在线观看 | 91视视频在线观看入口直接观看 | 日本欧美大片 | 国产乱码久久久 | 国产精品国产自产拍高清 | 日韩欧美二区 | 日韩视频观看 | 亚洲三级在线观看 | 精品国产精品三级精品av网址 | 精品亚洲一区二区三区四区五区 | 一区二区三区视频在线免费观看 | 久草网视频 | 国产精品自拍一区 | 成人免费精品视频 | 国产精品久久久久久久7电影 | 精品视频999 | 中文字幕成人 | 日韩一区二区三区视频 | 中文字幕电影在线观看 | 天天天久久久 | 韩国av一区二区 | 亚洲a视| 欧美精品一区免费 | 亚洲欧美一区二区三区国产精品 | 欧美福利 | 日韩免费视频一区二区 | 在线毛片网| 成人免费观看网站 | 精品电影| 成人免费影院 | 欧美日韩亚洲一区二区 | 精品99在线 | 久久久www成人免费无遮挡大片 | 国产精品久久久久久二区 | 日本视频免费 |