Ejemplo n.º 1
0
        private void panelRegionSelectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThumbnailPanel panel    = (ThumbnailPanel)panelContextMenuStrip.SourceControl;
            RegionSelector selector = new RegionSelector();

            selector.Load += (eventSender, eventArgs) =>
            {
                selector.SetWindow(panel.GetWindow(), panel.ClientAreaOnly);
                selector.DrawnRegion = panel.DrawnRegion;
            };
            if (selector.ShowDialog(this) == DialogResult.OK)
            {
                panel.DrawnRegion = selector.DrawnRegion;
            }
        }
Ejemplo n.º 2
0
        private void SetContextMenu(Thumbnail thumbnail)
        {
            ContextMenu contextMenu = new ContextMenu();

            MenuItem toggleItem = new MenuItem()
            {
                Header      = Globalization.UIMessages.ToggleClientOnlyMenuItem,
                IsCheckable = true,
            };
            Binding checkedBinding = new Binding("IsChecked")
            {
                Source = toggleItem,
            };

            thumbnail.SetBinding(Thumbnail.ClientAreaOnlyProperty, checkedBinding);
            contextMenu.Items.Add(toggleItem);

            MenuItem selectorItem = new MenuItem()
            {
                Header = Globalization.UIMessages.SelectRegionMenuItem,
            };
            Binding enabledBinding = new Binding("IsEnabled")
            {
                Source    = selectorItem,
                Converter = Converters.BooleanToggleConverter.Instance,
                Mode      = BindingMode.OneWayToSource,
            };

            toggleItem.SetBinding(MenuItem.IsCheckedProperty, enabledBinding);
            selectorItem.Click += (sender, e) =>
            {
                Rect           region   = thumbnail.DrawnRegion;
                RegionSelector selector = new RegionSelector();
                selector.thumbnail.Scale          = Math.Min(RegionSelector.ViewerWidth / region.Width, RegionSelector.ViewerHeight / region.Height);
                selector.thumbnail.ClientAreaOnly = thumbnail.ClientAreaOnly;
                selector.Loaded += (a, b) =>
                {
                    selector.Background = Brushes.Transparent;
                    selector.ExtendFrame(RegionSelector.AeroRegion, Colors.Transparent);
                    selector.thumbnail.SetWindow(thumbnail.Target);
                    selector.SourceX      = region.X;
                    selector.SourceY      = region.Y;
                    selector.SourceWidth  = region.Width;
                    selector.SourceHeight = region.Height;
                };
                selector.ContentRendered += (a, b) =>
                {
                    selector.thumbnail.DrawnRegion = region;
                };
                if (selector.ShowDialog().GetValueOrDefault(false) == true)
                {
                    thumbnail.DrawnRegion = selector.thumbnail.DrawnRegion;
                }
            };
            contextMenu.Items.Add(selectorItem);

            contextMenu.Items.Add(new Separator());

            MenuItem removeItem = new MenuItem()
            {
                Header = Globalization.UIMessages.RemoveMenuItem,
            };

            removeItem.Click += (sender, e) =>
            {
                thumbnail.Dispose();
                canvas.Children.Remove(thumbnail);
            };
            contextMenu.Items.Add(removeItem);

            thumbnail.ContextMenu = contextMenu;
        }