用SetLayeredWindowAttributes设置winform界面透明化

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace opacity
{
    public partial class Form1 : Form
    {
    
        [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
        private static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);
     public Form1()
        {
            InitializeComponent();
            this.BackColor = Color.FromArgb(255, 255, 255);
this.Opacity = 0.5;
SetLayeredWindowAttributes(Handle, 0xffffff, 0, 1); } } }

 

上一篇:手把手教你用WinForm制作地图编辑工具(一)


下一篇:Winform中生成自动控件