分享

WPF 开发的实用小工具(附源码)持续更新

 丹枫无迹 2021-03-15

前言



【update】

1、新增托盘。

2、新增换肤。

3、透明度切换。

环境

Visual Studio 2019,dotNet Framework 4.0 SDK

本项目采用MVVM模式。

1.获取主监视器上工作区域的尺寸。

2.并设置当前主窗体高度,设置窗体的Left与Top 到最右侧。

       private Rect desktopWorkingArea;       
       desktopWorkingArea =.Height = desktopWorkingArea.Height / .Left = desktopWorkingArea.Width - .Top = desktopWorkingArea.Height /  - (.Height / );

 

 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

 新更新 滚动增加动画

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多