Esempio n. 1
0
        /// <summary>
        ///   Generates the <see cref="RadioButton" /> controls and aligns the <see cref="screensBackground" /> <see cref="Canvas" />.
        /// </summary>
        private void GenerateScreenBorders()
        {
            // Remove old borders.
            foreach (RadioButton screen in this.screens)
            {
                this.Content.Children.Remove(screen);
            }
            this.screens.Clear();

            // The control's measure has to be set before the screens can be generated.
            if ((this.ActualWidth > 0) && (this.ActualHeight > 0))
            {
                System.Drawing.Rectangle allScreensBounds = new System.Drawing.Rectangle();

                for (Int32 i = 0; i < Screen.AllScreens.Length; i++)
                {
                    allScreensBounds = System.Drawing.Rectangle.Union(Screen.AllScreens[i].Bounds, allScreensBounds);
                }

                Double horizontalFactor = (this.Content.ActualWidth / allScreensBounds.Width);
                Double verticalFactor   = (this.Content.ActualHeight / allScreensBounds.Height);
                Double scaleFactor;

                if (horizontalFactor < verticalFactor)
                {
                    scaleFactor = horizontalFactor;
                }
                else
                {
                    scaleFactor = verticalFactor;
                }

                allScreensBounds = allScreensBounds.ScaleFull(scaleFactor);

                Int32 xAdd = 0;
                Int32 yAdd = 0;
                if (allScreensBounds.X < 0)
                {
                    xAdd = Math.Abs(allScreensBounds.X);
                }
                if (allScreensBounds.Y < 0)
                {
                    yAdd = Math.Abs(allScreensBounds.Y);
                }

                // Put the fullBounds rectangle into the center.
                allScreensBounds.X = (Int32)((this.Content.ActualWidth - allScreensBounds.Width) / 2.00);
                allScreensBounds.Y = (Int32)((this.Content.ActualHeight - allScreensBounds.Height) / 2.00);

                // Set the position and size of the preview ViewBox.
                Canvas.SetLeft(this.screensBackground, allScreensBounds.X + 4);
                Canvas.SetTop(this.screensBackground, allScreensBounds.Y + 4);
                this.screensBackground.Width  = allScreensBounds.Width - 7;
                this.screensBackground.Height = allScreensBounds.Height - 7;

                // Create preview screen border objects.
                for (Int32 i = 0; i < Screen.AllScreens.Length; i++)
                {
                    System.Drawing.Rectangle screenBounds = Screen.AllScreens[i].Bounds;
                    screenBounds    = screenBounds.ScaleFull(scaleFactor);
                    screenBounds.X += allScreensBounds.X + xAdd;
                    screenBounds.Y += allScreensBounds.Y + yAdd;

                    RadioButton screen = new RadioButton();
                    Canvas.SetLeft(screen, screenBounds.Left);
                    Canvas.SetTop(screen, screenBounds.Top);
                    screen.Width  = screenBounds.Width;
                    screen.Height = screenBounds.Height;
                    screen.SetResourceReference(FrameworkElement.StyleProperty, ScreenLayoutBox.ScreenRadioButtonStyleKey);
                    screen.IsChecked = (i == this.SelectedScreenIndex);
                    screen.Checked  += this.Screen_Checked;

                    DockPanel contentPanel = new DockPanel();

                    if (this.ShowScreenCheckBoxes)
                    {
                        CheckBox screenCheckBox = new CheckBox()
                        {
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Tag = i
                        };
                        if ((this.ScreensCheckStatus != null) && (i < this.ScreensCheckStatus.Count))
                        {
                            screenCheckBox.IsChecked = this.ScreensCheckStatus[i];
                        }
                        screenCheckBox.Click += this.ScreenCheckBox_Click;
                        screenCheckBox.SetResourceReference(FrameworkElement.StyleProperty, ScreenLayoutBox.ScreenCheckBoxStyleKey);
                        DockPanel.SetDock(screenCheckBox, Dock.Left);

                        contentPanel.Children.Add(screenCheckBox);
                    }

                    if (this.ShowScreenNumbers)
                    {
                        contentPanel.Children.Add(new TextBlock()
                        {
                            Text = (i + 1).ToString(CultureInfo.CurrentCulture),
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Center
                        });
                    }

                    screen.Content = contentPanel;
                    this.screens.Add(screen);

                    this.Content.Children.Add(screen);
                }
            }
        }