コード例 #1
0
ファイル: FontDialog.cs プロジェクト: JianchengZh/kasicass
        public FontDialog()
        {
            Title = "Font";
            ShowInTaskbar = false;
            WindowStyle = WindowStyle.ToolWindow;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;

            Grid gridMain = new Grid();
            Content = gridMain;

            RowDefinition rowdef = new RowDefinition();
            rowdef.Height = new GridLength(200, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            rowdef = new RowDefinition();
            rowdef.Height = new GridLength(150, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            ColumnDefinition coldef = new ColumnDefinition();
            coldef.Width = new GridLength(650, GridUnitType.Pixel);
            gridMain.ColumnDefinitions.Add(coldef);

            Grid gridBoxes = new Grid();
            gridMain.Children.Add(gridBoxes);

            rowdef = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridBoxes.RowDefinitions.Add(rowdef);

            rowdef = new RowDefinition();
            rowdef.Height = new GridLength(100, GridUnitType.Star);
            gridBoxes.RowDefinitions.Add(rowdef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(175, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(75, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            Label lbl = new Label();
            lbl.Content = "Font Family";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 0);

            boxFamily = new TextBoxWithLister();
            boxFamily.IsReadOnly = true;
            boxFamily.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxFamily);
            Grid.SetRow(boxFamily, 1);
            Grid.SetColumn(boxFamily, 0);

            lbl = new Label();
            lbl.Content = "Style";
            lbl.Margin = new Thickness(12,12,12,0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 1);

            boxStyle = new TextBoxWithLister();
            boxStyle.IsReadOnly = true;
            boxStyle.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStyle);
            Grid.SetRow(boxStyle, 1);
            Grid.SetColumn(boxStyle, 1);

            lbl = new Label();
            lbl.Content = "Weight";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 2);

            boxWeight = new TextBoxWithLister();
            boxWeight.IsReadOnly = true;
            boxWeight.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxWeight);
            Grid.SetRow(boxWeight, 1);
            Grid.SetColumn(boxWeight, 2);

            lbl = new Label();
            lbl.Content = "Stretch";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 3);

            boxStretch = new TextBoxWithLister();
            boxStretch.IsReadOnly = true;
            boxStretch.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStretch);
            Grid.SetRow(boxStretch, 1);
            Grid.SetColumn(boxStretch, 3);

            lbl = new Label();
            lbl.Content = "Size";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 4);

            boxSize = new TextBoxWithLister();
            boxSize.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxSize);
            Grid.SetRow(boxSize, 1);
            Grid.SetColumn(boxSize, 4);

            lblDisplay = new Label();
            lblDisplay.Content = "AbBbCC XxYyZz 012345";
            lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblDisplay.VerticalContentAlignment = VerticalAlignment.Center;
            gridMain.Children.Add(lblDisplay);
            Grid.SetRow(lblDisplay, 1);

            Grid gridButtons = new Grid();
            gridMain.Children.Add(gridButtons);
            Grid.SetRow(gridButtons, 2);

            for (int i = 0; i < 5; i++)
                gridButtons.ColumnDefinitions.Add(new ColumnDefinition());

            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 60;
            btn.Margin = new Thickness(12);
            btn.Click += OkOnClick;
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 1);

            btn = new Button();
            btn.Content = "Cancel";
            btn.IsCancel = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 60;
            btn.Margin = new Thickness(12);
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 3);

            foreach (FontFamily fam in Fonts.SystemFontFamilies)
                boxFamily.Add(fam);

            double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20,
                22, 24, 26, 28, 36, 48, 72 };
            foreach (double ptsize in ptsizes)
                boxSize.Add(ptsize);

            boxFamily.SelectionChanged += FamilyOnSelectionChanged;
            boxStyle.SelectionChanged += StyleOnSelectionChanged;
            boxWeight.SelectionChanged += StyleOnSelectionChanged;
            boxStretch.SelectionChanged += StyleOnSelectionChanged;
            boxSize.TextChanged += SizeOnTextChanged;

            Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
            FaceSize = FontSize;

            boxFamily.Focus();
            isUpdateSuppressed = false;
            UpdateSample();
        }
コード例 #2
0
        // Constructor.
        public FontDialog()
        {
            Title = "Font";
            ShowInTaskbar = false;
            WindowStyle = WindowStyle.ToolWindow;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;

            // Create three-row Grid as content of window.
            Grid gridMain = new Grid();
            Content = gridMain;

            // This row is for the TextBoxWithLister controls.
            RowDefinition rowdef = new RowDefinition();
            rowdef.Height = new GridLength(200, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            // This row is for the sample text.
            rowdef = new RowDefinition();
            rowdef.Height = new GridLength(150, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            // This row is for the buttons.
            rowdef = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridMain.RowDefinitions.Add(rowdef);

            // One column in main Grid.
            ColumnDefinition coldef = new ColumnDefinition();
            coldef.Width = new GridLength(650, GridUnitType.Pixel);
            gridMain.ColumnDefinitions.Add(coldef);

            // Create two-row, five-column Grid for TextBoxWithLister controls.
            Grid gridBoxes = new Grid();
            gridMain.Children.Add(gridBoxes);

            // This row is for the labels.
            rowdef = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridBoxes.RowDefinitions.Add(rowdef);

            // This row is for the EditBoxWithLister controls.
            rowdef = new RowDefinition();
            rowdef.Height = new GridLength(100, GridUnitType.Star);
            gridBoxes.RowDefinitions.Add(rowdef);

            // First column is FontFamily.
            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(175, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Second column is FontStyle.
            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Third column is FontWeight.
            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Fourth column is FontStretch.
            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Fifth column is Size.
            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(75, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Create FontFamily labels and TextBoxWithLister controls.
            Label lbl = new Label();
            lbl.Content = "Font Family";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 0);

            boxFamily = new TextBoxWithLister();
            boxFamily.IsReadOnly = true;
            boxFamily.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxFamily);
            Grid.SetRow(boxFamily, 1);
            Grid.SetColumn(boxFamily, 0);

            // Create FontStyle labels and TextBoxWithLister controls.
            lbl = new Label();
            lbl.Content = "Style";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 1);

            boxStyle = new TextBoxWithLister();
            boxStyle.IsReadOnly = true;
            boxStyle.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStyle);
            Grid.SetRow(boxStyle, 1);
            Grid.SetColumn(boxStyle, 1);

            // Create FontWeight labels and TextBoxWithLister controls.
            lbl = new Label();
            lbl.Content = "Weight";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 2);

            boxWeight = new TextBoxWithLister();
            boxWeight.IsReadOnly = true;
            boxWeight.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxWeight);
            Grid.SetRow(boxWeight, 1);
            Grid.SetColumn(boxWeight, 2);

            // Create FontStretch labels and TextBoxWithLister controls.
            lbl = new Label();
            lbl.Content = "Stretch";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 3);

            boxStretch = new TextBoxWithLister();
            boxStretch.IsReadOnly = true;
            boxStretch.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStretch);
            Grid.SetRow(boxStretch, 1);
            Grid.SetColumn(boxStretch, 3);

            // Create Size labels and TextBoxWithLister controls.
            lbl = new Label();
            lbl.Content = "Size";
            lbl.Margin = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 4);

            boxSize = new TextBoxWithLister();
            boxSize.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxSize);
            Grid.SetRow(boxSize, 1);
            Grid.SetColumn(boxSize, 4);

            // Create Label to display sample text.
            lblDisplay = new Label();
            lblDisplay.Content = "AaBbCc XxYzZz 012345";
            lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblDisplay.VerticalContentAlignment = VerticalAlignment.Center;
            gridMain.Children.Add(lblDisplay);
            Grid.SetRow(lblDisplay, 1);

            // Create five-column Grid for Buttons.
            Grid gridButtons = new Grid();
            gridMain.Children.Add(gridButtons);
            Grid.SetRow(gridButtons, 2);

            for (int i = 0; i < 5; i++)
                gridButtons.ColumnDefinitions.Add(new ColumnDefinition());

            // OK button.
            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 60;
            btn.Margin = new Thickness(12);
            btn.Click += OkOnClick;
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 1);

            // Cancel button.
            btn = new Button();
            btn.Content = "Cancel";
            btn.IsCancel = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 60;
            btn.Margin = new Thickness(12);
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 3);

            // Initialize FontFamily box with system font families.
            foreach (FontFamily fam in Fonts.SystemFontFamilies)
                   boxFamily.Add(fam);

            // Initialize FontSize box.
            double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18,
                                              20, 22, 24, 26, 28, 36, 48, 72 };
            foreach (double ptsize in ptsizes)
                boxSize.Add(ptsize);

            // Set event handlers.
            boxFamily.SelectionChanged += FamilyOnSelectionChanged;
            boxStyle.SelectionChanged += StyleOnSelectionChanged;
            boxWeight.SelectionChanged += StyleOnSelectionChanged;
            boxStretch.SelectionChanged += StyleOnSelectionChanged;
            boxSize.TextChanged += SizeOnTextChanged;

            // Initialize selected values based on Window properties.
            // (These will probably be overridden when properties are set.)
            Typeface = new Typeface(FontFamily, FontStyle,
                                    FontWeight, FontStretch);
            FaceSize = FontSize;

            // Set keyboard focus.
            boxFamily.Focus();

            // Allow updates to the sample text.
            isUpdateSuppressed = false;
            UpdateSample();
        }
コード例 #3
0
        // Constructor.
        public FontDialog()
        {
            Title                 = "Font";
            ShowInTaskbar         = false;
            WindowStyle           = WindowStyle.ToolWindow;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            SizeToContent         = SizeToContent.WidthAndHeight;
            ResizeMode            = ResizeMode.NoResize;

            // Create three-row Grid as content of window.
            Grid gridMain = new Grid();

            Content = gridMain;

            // This row is for the TextBoxWithLister controls.
            RowDefinition rowdef = new RowDefinition();

            rowdef.Height = new GridLength(200, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            // This row is for the sample text.
            rowdef        = new RowDefinition();
            rowdef.Height = new GridLength(150, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            // This row is for the buttons.
            rowdef        = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridMain.RowDefinitions.Add(rowdef);

            // One column in main Grid.
            ColumnDefinition coldef = new ColumnDefinition();

            coldef.Width = new GridLength(650, GridUnitType.Pixel);
            gridMain.ColumnDefinitions.Add(coldef);

            // Create two-row, five-column Grid for TextBoxWithLister controls.
            Grid gridBoxes = new Grid();

            gridMain.Children.Add(gridBoxes);

            // This row is for the labels.
            rowdef        = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridBoxes.RowDefinitions.Add(rowdef);

            // This row is for the EditBoxWithLister controls.
            rowdef        = new RowDefinition();
            rowdef.Height = new GridLength(100, GridUnitType.Star);
            gridBoxes.RowDefinitions.Add(rowdef);

            // First column is FontFamily.
            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(175, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Second column is FontStyle.
            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Third column is FontWeight.
            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Fourth column is FontStretch.
            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Fifth column is Size.
            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(75, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            // Create FontFamily labels and TextBoxWithLister controls.
            Label lbl = new Label();

            lbl.Content = "Font Family";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 0);

            boxFamily            = new TextBoxWithLister();
            boxFamily.IsReadOnly = true;
            boxFamily.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxFamily);
            Grid.SetRow(boxFamily, 1);
            Grid.SetColumn(boxFamily, 0);

            // Create FontStyle labels and TextBoxWithLister controls.
            lbl         = new Label();
            lbl.Content = "Style";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 1);

            boxStyle            = new TextBoxWithLister();
            boxStyle.IsReadOnly = true;
            boxStyle.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStyle);
            Grid.SetRow(boxStyle, 1);
            Grid.SetColumn(boxStyle, 1);

            // Create FontWeight labels and TextBoxWithLister controls.
            lbl         = new Label();
            lbl.Content = "Weight";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 2);

            boxWeight            = new TextBoxWithLister();
            boxWeight.IsReadOnly = true;
            boxWeight.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxWeight);
            Grid.SetRow(boxWeight, 1);
            Grid.SetColumn(boxWeight, 2);

            // Create FontStretch labels and TextBoxWithLister controls.
            lbl         = new Label();
            lbl.Content = "Stretch";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 3);

            boxStretch            = new TextBoxWithLister();
            boxStretch.IsReadOnly = true;
            boxStretch.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStretch);
            Grid.SetRow(boxStretch, 1);
            Grid.SetColumn(boxStretch, 3);

            // Create Size labels and TextBoxWithLister controls.
            lbl         = new Label();
            lbl.Content = "Size";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 4);

            boxSize        = new TextBoxWithLister();
            boxSize.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxSize);
            Grid.SetRow(boxSize, 1);
            Grid.SetColumn(boxSize, 4);

            // Create Label to display sample text.
            lblDisplay         = new Label();
            lblDisplay.Content = "AaBbCc XxYzZz 012345";
            lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblDisplay.VerticalContentAlignment   = VerticalAlignment.Center;
            gridMain.Children.Add(lblDisplay);
            Grid.SetRow(lblDisplay, 1);

            // Create five-column Grid for Buttons.
            Grid gridButtons = new Grid();

            gridMain.Children.Add(gridButtons);
            Grid.SetRow(gridButtons, 2);

            for (int i = 0; i < 5; i++)
            {
                gridButtons.ColumnDefinitions.Add(new ColumnDefinition());
            }

            // OK button.
            Button btn = new Button();

            btn.Content             = "OK";
            btn.IsDefault           = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth            = 60;
            btn.Margin = new Thickness(12);
            btn.Click += OkOnClick;
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 1);

            // Cancel button.
            btn                     = new Button();
            btn.Content             = "Cancel";
            btn.IsCancel            = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth            = 60;
            btn.Margin              = new Thickness(12);
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 3);

            // Initialize FontFamily box with system font families.
            foreach (FontFamily fam in Fonts.SystemFontFamilies)
            {
                boxFamily.Add(fam);
            }

            // Initialize FontSize box.
            double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18,
                                              20, 22, 24, 26, 28, 36, 48, 72 };
            foreach (double ptsize in ptsizes)
            {
                boxSize.Add(ptsize);
            }

            // Set event handlers.
            boxFamily.SelectionChanged  += FamilyOnSelectionChanged;
            boxStyle.SelectionChanged   += StyleOnSelectionChanged;
            boxWeight.SelectionChanged  += StyleOnSelectionChanged;
            boxStretch.SelectionChanged += StyleOnSelectionChanged;
            boxSize.TextChanged         += SizeOnTextChanged;

            // Initialize selected values based on Window properties.
            // (These will probably be overridden when properties are set.)
            Typeface = new Typeface(FontFamily, FontStyle,
                                    FontWeight, FontStretch);
            FaceSize = FontSize;

            // Set keyboard focus.
            boxFamily.Focus();

            // Allow updates to the sample text.
            isUpdateSuppressed = false;
            UpdateSample();
        }
コード例 #4
0
ファイル: FontDialog.cs プロジェクト: stevexy/kasicass
        public FontDialog()
        {
            Title                 = "Font";
            ShowInTaskbar         = false;
            WindowStyle           = WindowStyle.ToolWindow;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            SizeToContent         = SizeToContent.WidthAndHeight;
            ResizeMode            = ResizeMode.NoResize;

            Grid gridMain = new Grid();

            Content = gridMain;

            RowDefinition rowdef = new RowDefinition();

            rowdef.Height = new GridLength(200, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            rowdef        = new RowDefinition();
            rowdef.Height = new GridLength(150, GridUnitType.Pixel);
            gridMain.RowDefinitions.Add(rowdef);

            ColumnDefinition coldef = new ColumnDefinition();

            coldef.Width = new GridLength(650, GridUnitType.Pixel);
            gridMain.ColumnDefinitions.Add(coldef);

            Grid gridBoxes = new Grid();

            gridMain.Children.Add(gridBoxes);

            rowdef        = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            gridBoxes.RowDefinitions.Add(rowdef);

            rowdef        = new RowDefinition();
            rowdef.Height = new GridLength(100, GridUnitType.Star);
            gridBoxes.RowDefinitions.Add(rowdef);

            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(175, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(100, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            coldef       = new ColumnDefinition();
            coldef.Width = new GridLength(75, GridUnitType.Star);
            gridBoxes.ColumnDefinitions.Add(coldef);

            Label lbl = new Label();

            lbl.Content = "Font Family";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 0);

            boxFamily            = new TextBoxWithLister();
            boxFamily.IsReadOnly = true;
            boxFamily.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxFamily);
            Grid.SetRow(boxFamily, 1);
            Grid.SetColumn(boxFamily, 0);

            lbl         = new Label();
            lbl.Content = "Style";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 1);

            boxStyle            = new TextBoxWithLister();
            boxStyle.IsReadOnly = true;
            boxStyle.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStyle);
            Grid.SetRow(boxStyle, 1);
            Grid.SetColumn(boxStyle, 1);

            lbl         = new Label();
            lbl.Content = "Weight";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 2);

            boxWeight            = new TextBoxWithLister();
            boxWeight.IsReadOnly = true;
            boxWeight.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxWeight);
            Grid.SetRow(boxWeight, 1);
            Grid.SetColumn(boxWeight, 2);

            lbl         = new Label();
            lbl.Content = "Stretch";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 3);

            boxStretch            = new TextBoxWithLister();
            boxStretch.IsReadOnly = true;
            boxStretch.Margin     = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxStretch);
            Grid.SetRow(boxStretch, 1);
            Grid.SetColumn(boxStretch, 3);

            lbl         = new Label();
            lbl.Content = "Size";
            lbl.Margin  = new Thickness(12, 12, 12, 0);
            gridBoxes.Children.Add(lbl);
            Grid.SetRow(lbl, 0);
            Grid.SetColumn(lbl, 4);

            boxSize        = new TextBoxWithLister();
            boxSize.Margin = new Thickness(12, 0, 12, 12);
            gridBoxes.Children.Add(boxSize);
            Grid.SetRow(boxSize, 1);
            Grid.SetColumn(boxSize, 4);

            lblDisplay         = new Label();
            lblDisplay.Content = "AbBbCC XxYyZz 012345";
            lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblDisplay.VerticalContentAlignment   = VerticalAlignment.Center;
            gridMain.Children.Add(lblDisplay);
            Grid.SetRow(lblDisplay, 1);

            Grid gridButtons = new Grid();

            gridMain.Children.Add(gridButtons);
            Grid.SetRow(gridButtons, 2);

            for (int i = 0; i < 5; i++)
            {
                gridButtons.ColumnDefinitions.Add(new ColumnDefinition());
            }

            Button btn = new Button();

            btn.Content             = "OK";
            btn.IsDefault           = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth            = 60;
            btn.Margin = new Thickness(12);
            btn.Click += OkOnClick;
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 1);

            btn                     = new Button();
            btn.Content             = "Cancel";
            btn.IsCancel            = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth            = 60;
            btn.Margin              = new Thickness(12);
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 3);

            foreach (FontFamily fam in Fonts.SystemFontFamilies)
            {
                boxFamily.Add(fam);
            }

            double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20,
                                              22, 24, 26, 28, 36, 48, 72 };
            foreach (double ptsize in ptsizes)
            {
                boxSize.Add(ptsize);
            }

            boxFamily.SelectionChanged  += FamilyOnSelectionChanged;
            boxStyle.SelectionChanged   += StyleOnSelectionChanged;
            boxWeight.SelectionChanged  += StyleOnSelectionChanged;
            boxStretch.SelectionChanged += StyleOnSelectionChanged;
            boxSize.TextChanged         += SizeOnTextChanged;

            Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
            FaceSize = FontSize;

            boxFamily.Focus();
            isUpdateSuppressed = false;
            UpdateSample();
        }
コード例 #5
0
        // ctor
        public FontDialog()
        {
            Title                 = "Font";
            ShowInTaskbar         = false;
            WindowStyle           = WindowStyle.ToolWindow;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            SizeToContent         = SizeToContent.WidthAndHeight;
            ResizeMode            = ResizeMode.NoResize;

            // Grid with 3 rows
            Grid gridMain = new Grid();

            Content = gridMain;

            // row for TextBoxWithLister
            RowDefinition rowdef = new RowDefinition()
            {
                Height = new GridLength(200, GridUnitType.Pixel)
            };

            gridMain.RowDefinitions.Add(rowdef);

            // row for text sample
            rowdef = new RowDefinition()
            {
                Height = new GridLength(150, GridUnitType.Pixel)
            };
            gridMain.RowDefinitions.Add(rowdef);

            // row for buttons
            rowdef = new RowDefinition()
            {
                Height = GridLength.Auto
            };
            gridMain.RowDefinitions.Add(rowdef);

            // the only column of this Grid
            ColumnDefinition coldef = new ColumnDefinition()
            {
                Width = new GridLength(650, GridUnitType.Pixel)
            };

            gridMain.ColumnDefinitions.Add(coldef);

            // Grid 2x5 for TextBoxWithLister
            Grid gridBoxes = new Grid();

            gridMain.Children.Add(gridBoxes);

            // row for Labels
            rowdef = new RowDefinition()
            {
                Height = GridLength.Auto
            };
            gridBoxes.RowDefinitions.Add(rowdef);

            // row for TextBoxWithLister
            rowdef = new RowDefinition()
            {
                Height = new GridLength(100, GridUnitType.Star)
            };
            gridBoxes.RowDefinitions.Add(rowdef);

            // 1 column (FontFamily)
            coldef = new ColumnDefinition()
            {
                Width = new GridLength(175, GridUnitType.Star)
            };
            gridBoxes.ColumnDefinitions.Add(coldef);

            // 2 column (FontStyle)
            coldef = new ColumnDefinition()
            {
                Width = new GridLength(100, GridUnitType.Star)
            };
            gridBoxes.ColumnDefinitions.Add(coldef);

            // 3 column (FontWeight)
            coldef = new ColumnDefinition()
            {
                Width = new GridLength(100, GridUnitType.Star)
            };
            gridBoxes.ColumnDefinitions.Add(coldef);

            // 4 column (FontStretch)
            coldef = new ColumnDefinition()
            {
                Width = new GridLength(100, GridUnitType.Star)
            };
            gridBoxes.ColumnDefinitions.Add(coldef);

            // 5 columns (FaceSize)
            coldef = new ColumnDefinition()
            {
                Width = new GridLength(75, GridUnitType.Star)
            };
            gridBoxes.ColumnDefinitions.Add(coldef);


            // create Labels and TBWL for FontFamily

            // FontFamily
            TBWLAddToGrid(ref boxFamily, ref gridBoxes, 0, "Font Family");

            // FontStyle
            TBWLAddToGrid(ref boxStyle, ref gridBoxes, 1, "Style");

            // FontWeight
            TBWLAddToGrid(ref boxWeight, ref gridBoxes, 2, "Weight");

            // FontStretch
            TBWLAddToGrid(ref boxStretch, ref gridBoxes, 3, "Stretch");

            // FaceSize
            TBWLAddToGrid(ref boxSize, ref gridBoxes, 4, "Size");

            // sample Label
            lblDisplay = new Label()
            {
                Content             = "AaBbCc XxYyZz 012345",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };
            gridMain.Children.Add(lblDisplay);
            Grid.SetRow(lblDisplay, 1);

            // Grid 1x5 for buttons
            Grid gridButtons = new Grid();

            gridMain.Children.Add(gridButtons);
            Grid.SetRow(gridButtons, 2);
            for (int i = 0; i < 5; i++)
            {
                gridButtons.ColumnDefinitions.Add(new ColumnDefinition());
            }

            // OK button
            Button btn = new Button()
            {
                Content             = "OK",
                IsDefault           = true,
                HorizontalAlignment = HorizontalAlignment.Center,
                MinWidth            = 60,
                Margin = new Thickness(12)
            };

            btn.Click += OkOnClick;
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 1);

            // Cancel button
            btn = new Button()
            {
                Content             = "Cancel",
                IsCancel            = true,
                HorizontalAlignment = HorizontalAlignment.Center,
                MinWidth            = 60,
                Margin = new Thickness(12)
            };
            gridButtons.Children.Add(btn);
            Grid.SetColumn(btn, 3);

            // init FontFamily with system fonts
            foreach (FontFamily fam in Fonts.SystemFontFamilies)
            {
                boxFamily.Add(fam);
            }

            // init FontSize
            double[] ptSizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
            foreach (double ptSize in ptSizes)
            {
                boxSize.Add(ptSize);
            }

            // set event handlers
            boxFamily.SelectionChanged  += FamilyOnSelectionChanged;
            boxStyle.SelectionChanged   += StyleOnSelectionChanged;
            boxWeight.SelectionChanged  += StyleOnSelectionChanged;
            boxStretch.SelectionChanged += StyleOnSelectionChanged;
            boxSize.SelectionChanged    += SizeOnSelectionChanged;

            // init first selections
            Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
            FaceSize = FontSize;

            // take a focus
            boxFamily.Focus();

            // allow updates
            isUpdateSuppressed = false;
            UpdateSample();
        }