欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)懸浮窗口的方法詳解

 更新時(shí)間:2022年12月21日 11:14:44   作者:鋼鐵男兒  
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)懸浮窗口的相關(guān)資料,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以了解一下

一 懸浮窗口

特點(diǎn):

① 窗口一般較小,有時(shí)為不規(guī)則背景;

② 置頂顯示;

③ 窗口支持拖動(dòng);

④ 一般用于程序狀態(tài)顯示,比如顯示下載進(jìn)度;

⑤ 一般支持右鍵菜單、拖拽操作等;

二 創(chuàng)建懸浮窗口

1 實(shí)現(xiàn)細(xì)節(jié)

① 無(wú)邊框FormBorderStyle:Noe;

② 置頂顯示TopMost:true;

③ 顯示位置StartPosition:Manual自由指定;

2 細(xì)節(jié)

對(duì)應(yīng)Form來(lái)說(shuō)先Show,后設(shè)置大小和位置

floatBox=new myFloatBox();
floatBox.Owner=this;
floatBox.Show();
floatBox.Bounds=new Rectangle(0,0,100,100);

三 圓形背景

代碼實(shí)現(xiàn):

① 添加一個(gè)正方形的圖片資源;

② 繪制圓形圖片;

③ 將外圍白色區(qū)域設(shè)為透明;

④ 繪制一個(gè)蒙版,確保中間區(qū)域沒(méi)有白色像素點(diǎn);

子窗體

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

namespace 圓形背景
{
    public partial class FloatingWindow : Form
    {
        private Image image;
        public FloatingWindow()
        {
            this.FormBorderStyle = FormBorderStyle.None;//無(wú)邊框
            this.StartPosition = FormStartPosition.Manual;//手工指定位置
            this.ShowInTaskbar = false;//在任務(wù)欄不顯示圖標(biāo)
            this.TopMost = true;//置頂顯示
            this.BackColor = Color.White;//背景色
            this.TransparencyKey = Color.White;//指定透明區(qū)域的顏色

            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;
            int w = this.Width, h = this.Height;
            Rectangle rect = new Rectangle(0, 0, w, h);
            rect.Inflate(-2, -2);

            //平滑繪制,反鋸齒
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            //繪制一個(gè)圓形的圖片
            if(true)
            {
                GraphicsPath path = new GraphicsPath();
                int radius = rect.Width / 2;
                int x = w / 2 - radius;
                int y = h / 2 - radius;
                path.AddEllipse(new Rectangle(x, y, radius * 2, radius * 2));

                //設(shè)置剪輯區(qū)域
                Region oldClip = g.Clip;
                g.Clip = new Region(path);

                //繪制圖像(Clip區(qū)域之外的部分不會(huì)顯示)
                if(this.image!=null)
                {
                    Console.WriteLine("圖像:" + image.Size);
                    Console.WriteLine("位置" + this.Size);
                    g.DrawImage(image, rect);
                }

                //覆蓋一層蒙版,確保純白色像素點(diǎn)不會(huì)出現(xiàn),因?yàn)榧儼咨峭该魃?
                Brush brush = new SolidBrush(Color.FromArgb(10, 255, 255, 255));
                g.FillRectangle(brush, rect);
                brush.Dispose();

                g.Clip.Dispose();
                g.Clip = oldClip;//恢復(fù)

                Pen pen = new Pen(Color.LightBlue);
                g.DrawPath(pen, path);
                pen.Dispose();
            }
        }

        public Image Image
        {
            get { return this.image; }
            set { this.image = value;
                this.Invalidate();
            }
        }
        
    }
}

父窗體

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 圓形背景
{
    public partial class Form1 : Form
    {
        FloatingWindow floatingWindow;
        public Form1()
        {
            InitializeComponent();

            floatingWindow=new FloatingWindow();
            floatingWindow.Show();
            floatingWindow.Bounds = new Rectangle(0, 0, 100, 100);

            //設(shè)置懸浮窗口的背景圖片
            floatingWindow.Image = Properties.Resources.XiaoWu;
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            floatingWindow.Dispose();
        }
    }
}

到此這篇關(guān)于C#實(shí)現(xiàn)懸浮窗口的方法詳解的文章就介紹到這了,更多相關(guān)C#懸浮窗口內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#?TrackBar拖動(dòng)條改變滑塊顏色

    C#?TrackBar拖動(dòng)條改變滑塊顏色

    這篇文章主要為大家詳細(xì)介紹了C#?TrackBar拖動(dòng)條改變滑塊顏色,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • 通過(guò)C#調(diào)用cmd來(lái)修改服務(wù)啟動(dòng)類(lèi)型

    通過(guò)C#調(diào)用cmd來(lái)修改服務(wù)啟動(dòng)類(lèi)型

    可以使用System.ServiceProcess.ServiceController這個(gè)類(lèi)允許連接到正在運(yùn)行或者已停止的服務(wù)、對(duì)其進(jìn)行操作或獲取有關(guān)它的信息但是這個(gè)類(lèi)并沒(méi)有提供修改服務(wù)啟動(dòng)類(lèi)型的方法,可以通過(guò)C#調(diào)用cmd來(lái)修改
    2012-12-12
  • c# 委托的本質(zhì)是什么

    c# 委托的本質(zhì)是什么

    這篇文章主要介紹了c# 委托的本質(zhì)是什么,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • C# 鍵值對(duì)數(shù)據(jù)排序代碼

    C# 鍵值對(duì)數(shù)據(jù)排序代碼

    這篇文章介紹了C# 鍵值對(duì)數(shù)據(jù)排序代碼,有需要的朋友可以參考一下
    2013-11-11
  • 一篇文章弄懂C#中的async和await

    一篇文章弄懂C#中的async和await

    這篇文章主要給大家介紹了如何通過(guò)一篇文章弄懂C#中async和await的相關(guān)資料,async和await相信大家應(yīng)該不陌生,讓異步處理變得更友好,本文通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-07-07
  • C#打包應(yīng)用程序,與.NETFramework介紹

    C#打包應(yīng)用程序,與.NETFramework介紹

    C#打包應(yīng)用程序,與.NETFramework介紹,需要的朋友可以參考一下
    2013-05-05
  • C#中IntPtr類(lèi)型的具體使用

    C#中IntPtr類(lèi)型的具體使用

    本文主要介紹了C#中IntPtr類(lèi)型的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • C# 啟用事務(wù)提交多條帶參數(shù)的SQL語(yǔ)句實(shí)例代碼

    C# 啟用事務(wù)提交多條帶參數(shù)的SQL語(yǔ)句實(shí)例代碼

    這篇文章主要介紹了C# 啟用事務(wù)提交多條帶參數(shù)的SQL語(yǔ)句實(shí)例代碼,需要的朋友可以參考下
    2018-02-02
  • C#獲取打印機(jī)列表方法介紹

    C#獲取打印機(jī)列表方法介紹

    這篇文章介紹了C#獲取打印機(jī)列表的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • WinForm使用正則表達(dá)式提取內(nèi)容的方法示例

    WinForm使用正則表達(dá)式提取內(nèi)容的方法示例

    這篇文章主要介紹了WinForm使用正則表達(dá)式提取內(nèi)容的方法,結(jié)合實(shí)例形式分析了WinForm基于正則匹配獲取指定內(nèi)容的相關(guān)操作技巧,需要的朋友可以參考下
    2017-05-05

最新評(píng)論