c# 实现透明窗体,透明图片,透明按钮

本文介绍了如何在PC上创建透明窗体,并通过调整参数实现半透明效果。此外,还详细展示了如何使用C#绘制半透明图片的方法,包括设置图像颜色属性等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.在PC上,透明窗体,只要改变 this.Ocapity=0.5就可以实现透明窗体。

2.透明图片的的实现方法:

 

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

 

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

           Graphics g = this.CreateGraphics();
            g.Clear(this.BackColor);

            Bitmap bitmap = new Bitmap(@"d:/photo.jpg");
            float[][] ptsArray ={
                                    new float[] {1, 0, 0, 0, 0},
                                    new float[] {0, 1, 0, 0, 0},
                                    new float[] {0, 0, 1, 0, 0},
                                    new float[] {0, 0, 0, 0.5f, 0}, //注意:此处为0.5f,图像为半透明
                                    new float[] {0, 0, 0, 0, 1}};

            ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
            ImageAttributes imgAttributes = new ImageAttributes();
            //设置图像的颜色属性
            imgAttributes.SetColorMatrix(clrMatrix,    ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            //画图像
            g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                0, 0, bitmap.Width, bitmap.Height,
                GraphicsUnit.Pixel, imgAttributes);

            g.Dispose();

}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值