• 大小: 330KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: winform  锯齿  

资源简介

透明图片作winform的背景去锯齿,绝对有效。采用双层窗体。能拖动

资源截图

代码片段和文件信息

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


namespace WindowsFormsApp1
{
    public partial class Skin : Form
    {
        public FormShow show;
        public Skin(FormShow show)
        {
            InitializeComponent();
            this.show = show;
            this.BackgroundImage = WindowsFormsApp3.Properties.Resource1.log_bg;//将背景图应用到皮肤层
            this.BackgroundImageLayout = ImageLayout.Stretch;//自动拉伸背景图以适应窗口
            this.Size = show.Size;//统一大小
            show.Owner = this;//设置控件层的拥有皮肤层

            Location = new Point(show.Location.X show.Location.Y);//统一控件层和皮肤层的位置
        }



        private void Form1_Load(object sender EventArgs e)
        {
            FormBorderstyle = FormBorderstyle.None;//取消窗口边框
            SetBits(new Bitmap(BackgroundImage new Size(135 70)));//设置不规则窗体
            FormMovableEvent();
        }
        bool haveHandle = false;//窗体句柄创建完成
        private void Initializestyles()
        {
            Setstyle(
                Controlstyles.UserPaint |
                Controlstyles.AllPaintingInWmPaint |
                Controlstyles.OptimizedDoubleBuffer |
                Controlstyles.ResizeRedraw |
                Controlstyles.SupportsTransparentBackColor true);
            Setstyle(Controlstyles.Selectable false);
            Updatestyles();
        }

        protected override void OnHandleCreated(EventArgs e)
        {
            Initializestyles();//设置窗口样式、双缓冲等
            base.OnHandleCreated(e);
            haveHandle = true;
        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cParms = base.CreateParams;
                cParms.Exstyle |= 0x00080000; // WS_EX_layerED
                return cParms;
            }
        }
        public void SetBits(Bitmap bitmap)
        {
            if (!haveHandle) return;

            if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
                throw new ApplicationException(“The picture must be 32bit picture with alpha channel.“);

            IntPtr oldBits = IntPtr.Zero;
            IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr memDc = Win32.CreateCompatibleDC(screenDC);

            try
            {
                Win32.Point topLoc = new Win32.Point(Left Top);
                Win32.Size bitMapSize = new Win32.Size(bitmap.Width bitmap.Height);
                Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();
                Win32.Point srcLoc = new Win32.Point(0 0);

                hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
                oldBits 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     54272  2018-04-21 17:13  不规则锯齿问题\.vs\WindowsFormsApp3\v15\.suo

     文件          0  2018-04-21 10:35  不规则锯齿问题\.vs\WindowsFormsApp3\v15\Server\sqlite3\db.lock

     文件    1171456  2018-04-21 17:13  不规则锯齿问题\.vs\WindowsFormsApp3\v15\Server\sqlite3\storage.ide

     文件        184  2018-04-21 10:44  不规则锯齿问题\WindowsFormsApp3\App.config

     文件      39936  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\bin\Debug\WindowsFormsApp3.exe

     文件        184  2018-04-21 10:44  不规则锯齿问题\WindowsFormsApp3\bin\Debug\WindowsFormsApp3.exe.config

     文件      34304  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\bin\Debug\WindowsFormsApp3.pdb

     文件       6534  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\FormMinSkin.cs

     文件       2045  2018-04-21 11:23  不规则锯齿问题\WindowsFormsApp3\FormMinSkin.designer.cs

     文件      24936  2018-04-21 11:23  不规则锯齿问题\WindowsFormsApp3\FormMinSkin.resx

     文件        974  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\FormShow.cs

     文件       2126  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\FormShow.designer.cs

     文件       5817  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\FormShow.resx

     文件       1164  2018-04-21 10:44  不规则锯齿问题\WindowsFormsApp3\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7123  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-04-21 10:35  不规则锯齿问题\WindowsFormsApp3\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-04-21 10:35  不规则锯齿问题\WindowsFormsApp3\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-04-21 10:35  不规则锯齿问题\WindowsFormsApp3\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       3584  2018-04-21 10:47  不规则锯齿问题\WindowsFormsApp3\obj\Debug\TempPE\Properties.Resource1.Designer.cs.dll

     文件       3584  2018-04-21 11:26  不规则锯齿问题\WindowsFormsApp3\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        180  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp1.FormShow.resources

     文件      13040  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp1.Skin.resources

     文件         42  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.csproj.CoreCompileInputs.cache

     文件       1262  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.csproj.FileListAbsolute.txt

     文件       1192  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.csproj.GenerateResource.cache

     文件      39936  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.exe

     文件      34304  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.pdb

     文件      13010  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.Properties.Resource1.resources

     文件        180  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\WindowsFormsApp3.Properties.Resources.resources

     文件         42  2018-04-21 17:12  不规则锯齿问题\WindowsFormsApp3\obj\Debug\不规则窗体.csproj.CoreCompileInputs.cache

............此处省略35个文件信息

评论

共有 条评论