博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# PicBox 背景透明
阅读量:6926 次
发布时间:2019-06-27

本文共 1044 字,大约阅读时间需要 3 分钟。

private void picBackground_Paint(object sender, PaintEventArgs e)

        {
            foreach (Control C in this.Controls)
            {
                if (C is Label)
                {

                    Label L = (Label)C;

                    L.Visible = false;

                    //设置绘制文字的格式  

                    StringFormat strFmt = new System.Drawing.StringFormat();
                    strFmt.Alignment = StringAlignment.Center; //文本垂直居中  
                    strFmt.LineAlignment = StringAlignment.Center; //文本水平居中  
                    e.Graphics.DrawString(L.Text, this.Font, new SolidBrush(this.ForeColor), new RectangleF(L.Left - picBackground.Left, L.Top - picBackground.Top, L.Width, L.Height), strFmt); 

                }

                else if (C is PictureBox)
                {
                    PictureBox L = (PictureBox)C;
                    if (!L.Name.Equals("picBackground"))
                    {
                        L.Visible = false;
                        ImageAttributes attrib = new ImageAttributes();
                        //Bitmap img = new Bitmap(L.Image);
                        Color color = Color.Transparent;
                        attrib.SetColorKey(color, color);
                        e.Graphics.DrawImage(L.Image, new Rectangle(L.Left - picBackground.Left, L.Top - picBackground.Top, L.Width, L.Height), 0, 0, L.Image.Width, L.Image.Height, GraphicsUnit.Pixel, attrib);
                    }
                }
            }
        }

转载于:https://www.cnblogs.com/xsmhero/archive/2012/08/02/2620262.html

你可能感兴趣的文章
基于Mesos的操作系统之RogerOS
查看>>
JS基础篇--事件绑定及深入
查看>>
Google 推出 Node 应用 Web 渲染界面 Carlo
查看>>
进一步成熟,Chrome OS 提供了更完整的 USB 支持
查看>>
Node.js ORM 框架 Sequelize 重要更新 v5 发布
查看>>
【meteor初体验-0.0.1】meteor简单开始
查看>>
Python 小试牛刀,Django详细解读,让你更快的掌握它!!! ...
查看>>
Selenium最全超时等待问题的处理方案
查看>>
微服务架构的中国式落地
查看>>
Git 实用指南
查看>>
大数据学习:带你从多个维度来分析大数据发展趋势 ...
查看>>
最小化 Java 镜像的常用技巧
查看>>
Swift 无限轮播图
查看>>
puppet连载四:服务端安装dashboard
查看>>
基于阿里云构建同城跨可用区的容灾解决方案
查看>>
二进制包20分钟快速安装部署 Kubernetes v1.14.0 集群 ...
查看>>
专访长亮科技李劲松:17年金融IT服务商的海外新机遇
查看>>
Linux基础命令---arping
查看>>
单季营收破千亿!中国首个!阿里要逆天
查看>>
会写代码是你创业路上的包袱吗?
查看>>