Beispiel #1
0
        public FormExtendsDpiAwareForm()
        {
            InitializeComponent();

            _contextMenuDpiHandler = contextMenuStrip1.AttachDpiHandler();

            _dpiChangeSubscription = _contextMenuDpiHandler.OnDpiChanged.Subscribe(dpi =>
            {
                Log.Info().WriteLine("ContextMenuStrip DPI: {0}", dpi.NewDpi);
            });

            // TODO: Create a "SizeScaleHandler" or something
            var initialMenuStripSize = menuStrip1.ImageScalingSize;

            FormDpiHandler.OnDpiChanged.Subscribe(dpiChangeInfo =>
            {
                menuStrip1.ImageScalingSize = DpiHandler.ScaleWithDpi(initialMenuStripSize, dpiChangeInfo.NewDpi);
            });

            _scaleHandler = BitmapScaleHandler.WithComponentResourceManager <Bitmap>(FormDpiHandler, GetType(), BitmapScaleHandler.SimpleBitmapScaler)
                            .AddTarget(somethingMenuItem, "somethingMenuItem.Image", b => b)
                            .AddTarget(something2MenuItem, "something2MenuItem.Image", b => b);

            EnvironmentMonitor.EnvironmentUpdateEvents.Subscribe(args =>
            {
                Log.Info().WriteLine("{0} - {1}", args.SystemParametersInfoAction, args.Area);
                MessageBox.Show(this, $@"{args.SystemParametersInfoAction} - {args.Area}", @"Change!");
            });
        }
        public FormWithAttachedDpiHandler()
        {
            FormDpiHandler = this.AttachDpiHandler();
            InitializeComponent();

            var initialMenuStripSize = menuStrip1.ImageScalingSize;

            FormDpiHandler.OnDpiChanged.Subscribe(dpiChangeInfo =>
            {
                menuStrip1.ImageScalingSize = DpiHandler.ScaleWithDpi(initialMenuStripSize, dpiChangeInfo.NewDpi);
            });

            _scaleHandler = BitmapScaleHandler.WithComponentResourceManager <Bitmap>(FormDpiHandler, GetType(), BitmapScaleHandler.SimpleBitmapScaler)
                            .AddTarget(somethingMenuItem, "somethingMenuItem.Image", b => b)
                            .AddTarget(something2MenuItem, "something2MenuItem.Image", b => b);

            // This can be used to do something with DPI changes, subscription should be disposed!
            _dpiChangeSubscription = FormDpiHandler.OnDpiChanged.Subscribe(dpi =>
            {
                Log.Info().WriteLine("New DPI: {0}", dpi);
            });

            EnvironmentMonitor.EnvironmentUpdateEvents.Subscribe(args =>
            {
                Log.Info().WriteLine("{0} - {1}", args.SystemParametersInfoAction, args.Area);
                MessageBox.Show(this, $@"{args.SystemParametersInfoAction} - {args.Area}", @"Change!");
            });
        }
Beispiel #3
0
        /// <summary>
        /// Setup the Bitmap scaling (for icons)
        /// </summary>
        private void SetupBitmapScaleHandler()
        {
            ContextMenuDpiHandler = contextMenu.AttachDpiHandler();

            var dpiChangeSubscription = DpiHandler.OnDpiChangeInfo.Subscribe(info =>
            {
                switch (info.DpiChangeEventType)
                {
                case DpiChangeEventTypes.Before:
                    // Change the ImageScalingSize before setting the bitmaps
                    var width = DpiHandler.ScaleWithDpi(coreConfiguration.IconSize.Width, info.NewDpi);
                    var size  = new Size(width, width);
                    contextMenu.SuspendLayout();
                    contextMenu.ImageScalingSize   = size;
                    contextmenu_quicksettings.Size = new Size(170, width + 8);
                    break;

                case DpiChangeEventTypes.After:
                    // Redraw the form
                    contextMenu.ResumeLayout(true);
                    contextMenu.Refresh();
                    notifyIcon.Icon = GreenshotResources.GetGreenshotIcon();
                    break;
                }
            });

            var contextMenuResourceScaleHandler = BitmapScaleHandler.WithComponentResourceManager(ContextMenuDpiHandler, GetType(), (bitmap, dpi) => bitmap.ScaleIconForDisplaying(dpi));

            contextMenuResourceScaleHandler.AddTarget(contextmenu_capturewindow, "contextmenu_capturewindow.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_capturearea, "contextmenu_capturearea.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_capturelastregion, "contextmenu_capturelastregion.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_capturefullscreen, "contextmenu_capturefullscreen.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_captureclipboard, "contextmenu_captureclipboard.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_openfile, "contextmenu_openfile.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_settings, "contextmenu_settings.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_help, "contextmenu_help.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_donate, "contextmenu_donate.Image");
            contextMenuResourceScaleHandler.AddTarget(contextmenu_exit, "contextmenu_exit.Image");

            // this is special handling, for the icons which come from the executables
            var exeBitmapScaleHandler = BitmapScaleHandler.Create <string>(ContextMenuDpiHandler,
                                                                           (path, dpi) => PluginUtils.GetCachedExeIcon(path, 0, dpi >= 120),
                                                                           (bitmap, dpi) => bitmap.ScaleIconForDisplaying(dpi));

            exeBitmapScaleHandler.AddTarget(contextmenu_captureie, PluginUtils.GetExePath("iexplore.exe"));

            // Add cleanup
            Application.ApplicationExit += (sender, args) =>
            {
                dpiChangeSubscription.Dispose();
                ContextMenuDpiHandler.Dispose();
                contextMenuResourceScaleHandler.Dispose();
                exeBitmapScaleHandler.Dispose();
            };
        }
Beispiel #4
0
        public FormExtendsDpiAwareForm()
        {
            InitializeComponent();

            _contextMenuDpiHandler = contextMenuStrip1.AttachDpiHandler();

            _contextMenuDpiHandler.OnDpiChanged.Subscribe(dpi =>
            {
                Log.Info().WriteLine("ContextMenuStrip DPI: {0}", dpi);
            });
            ScaleHandler = BitmapScaleHandler.WithComponentResourceManager(DpiHandler, GetType(), ScaleIconForDisplaying);

            ScaleHandler.AddTarget(somethingMenuItem, "somethingMenuItem.Image");
            ScaleHandler.AddTarget(something2MenuItem, "something2MenuItem.Image");

            EnvironmentMonitor.EnvironmentUpdateEvents.Subscribe(args =>
            {
                Log.Info().WriteLine("{0} - {1}", args.SystemParametersInfoAction, args.Area);
                MessageBox.Show(this, $"{args.SystemParametersInfoAction} - {args.Area}", "Change!");
            });
        }
Beispiel #5
0
        public FormWithAttachedDpiHandler()
        {
            _dpiHandler = this.AttachDpiHandler();
            InitializeComponent();
            ScaleHandler = BitmapScaleHandler.WithComponentResourceManager(_dpiHandler, GetType(), ScaleIconForDisplaying);

            // This can be used to do something with DPI changes, subscription should be disposed!
            _dpiChangeSubscription = _dpiHandler.OnDpiChanged.Subscribe(dpi =>
            {
                var width = DpiHandler.ScaleWithDpi(20, dpi);
                var size  = new Size(width, width);
                //menuStrip1.ImageScalingSize = size;
            });


            ScaleHandler.AddTarget(somethingMenuItem, "somethingMenuItem.Image");
            ScaleHandler.AddTarget(something2MenuItem, "something2MenuItem.Image");

            EnvironmentMonitor.EnvironmentUpdateEvents.Subscribe(args =>
            {
                Log.Info().WriteLine("{0} - {1}", args.SystemParametersInfoAction, args.Area);
                MessageBox.Show(this, $"{args.SystemParametersInfoAction} - {args.Area}", "Change!");
            });
        }
Beispiel #6
0
 /// <summary>
 /// Default constructor, for default functionality like DPI awareness
 /// </summary>
 protected GreenshotForm()
 {
     // Add the Dapplo.Windows DPI change handler
     ScaleHandler = BitmapScaleHandler.WithComponentResourceManager(DpiHandler, GetType(), (bitmap, dpi) => bitmap.ScaleIconForDisplaying(dpi));
 }