Exemple #1
0
        private void UpdateContextMenu()
        {
            var defaultPath = Path.GetFullPath(Properties.Settings.Default.DefaultPath);

            if (!Directory.Exists(defaultPath))
            {
                Directory.CreateDirectory(defaultPath);
            }
            var files = Directory.EnumerateFiles(defaultPath, "*.png").Reverse().Take(10).ToList();

            _ctxMenu = new ContextMenu();

            var listItems = new List <MenuItem>
            {
                new MenuItem("Einstellungen", ctx_Settings),
                new MenuItem("mit Windows starten", ctx_Autostart),
                new MenuItem($"letzten Bilder ({files.Count})"),
                new MenuItem("Beenden", (o, args) => Application.Exit())
            };

            var recentScreenshots = new List <MenuItem>();
            var regKey            = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            var regValue          = regKey?.GetValue(_appName);

            _ctxAutostart = regValue?.ToString() == AppPath;

            files.ForEach(file =>
            {
                var menuItem = new MenuItem(Path.GetFileName(file.ToString()), (o, args) =>
                {
                    using (var fs = new FileStream(file.ToString(), FileMode.Open))
                    {
                        var pic     = new Bitmap(fs);
                        var preview = new PreviewArea((Bitmap)pic.Clone(), file.ToString());
                        preview.Show();
                    }
                });
                recentScreenshots.Add(menuItem);
            });

            listItems[2].MenuItems.AddRange(recentScreenshots.ToArray());

            listItems[1].Checked = _ctxAutostart;

            //todo: Entfernen sobald fertig
            listItems[0].Enabled = false;

            _ctxMenu.MenuItems.AddRange(listItems.ToArray());

            Notifier.ContextMenu = _ctxMenu;
            _ctxMenu.Popup      += ctx_OnPopup;
        }
Exemple #2
0
        private void canevas_MouseUp(object sender, MouseEventArgs e)
        {
            if (_drawing)
            {
                _drawing = false;
                var rc = GetRectangle();
                if (rc.Width > 0 && rc.Height > 0)
                {
                    _rectangles.Add(rc);

                    var preview = new PreviewArea(TakeScreenshot(rc.X, rc.Y, rc.Width, rc.Height), string.Empty);
                    preview.Show();
                    Hide();
                }
                _canevas.Invalidate();
            }
        }