WPF 開發的實用小工具(附源碼)持續更新


前言

看最近比較冷清,我來暖暖場。

 點擊鏈接加入群聊

【update】

1、新增托盤。

2、新增換膚。

3、透明度切換。

環境

Visual Studio 2019,dotNet Framework 4.0 SDK

本項目采用MVVM模式。

1.獲取主監視器上工作區域的尺寸。

2.並設置當前主窗體高度,設置窗體的Left與Top 到最右側。

       private Rect desktopWorkingArea;       
       desktopWorkingArea = System.Windows.SystemParameters.WorkArea; this.Height = desktopWorkingArea.Height / 2; this.Left = desktopWorkingArea.Width - this.Width; this.Top = desktopWorkingArea.Height / 2 - (this.Height / 2);

 

 3.移動窗體只允許Y軸 移動,調用Win32 的 MoveWindow。

 #region 移動窗體
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            anchorPoint = e.GetPosition(this);
            inDrag = true;
            CaptureMouse();
            e.Handled = true;
        }
        
        protected override void OnMouseMove(MouseEventArgs e)
        {
            try
            {
                if (inDrag)
                {
                    System.Windows.Point currentPoint = e.GetPosition(this);
                    var y = this.Top + currentPoint.Y - anchorPoint.Y;
                    Win32Api.RECT rect;
                    Win32Api.GetWindowRect(new WindowInteropHelper(this).Handle, out rect);
                    var w = rect.right - rect.left;
                    var h = rect.bottom - rect.top;
                    int x = Convert.ToInt32(PrimaryScreen.DESKTOP.Width - w);

                    Win32Api.MoveWindow(new WindowInteropHelper(this).Handle, x, (int)y, w, h, 1);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"MainView.OnMouseMove{ex.Message}");
            }
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            if (inDrag)
            {
                ReleaseMouseCapture();
                inDrag = false;
                e.Handled = true;
            }
        }
        #endregion

4.在Tab鍵+Alt鍵切換時隱藏當前窗體。

WindowInteropHelper wndHelper = new WindowInteropHelper(this);

            int exStyle = (int)Win32Api.GetWindowLong(wndHelper.Handle, (int)Win32Api.GetWindowLongFields.GWL_EXSTYLE);

            exStyle |= (int)Win32Api.ExtendedWindowStyles.WS_EX_TOOLWINDOW;
            Win32Api.SetWindowLong(wndHelper.Handle, (int)Win32Api.GetWindowLongFields.GWL_EXSTYLE, (IntPtr)exStyle);

 

 5.在窗體加載完成去注冊表讀取安裝的應用(還有系統桌面),獲取應用路徑后提取.ICO轉換為.PNG保存。

 

 

6.剩下的代碼都是wpf中的動畫和自動定義控件的代碼。

效果圖預覽

 2020/11/09

 新更新 滾動增加動畫

 

 源碼下載地址

 gitee

下載解壓后體驗


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM