Exemplo n.º 1
0
        //***************************************************************
        // RichEditBox MenuFlyoutItem Click Events for different menus
        //***************************************************************
        private void MnFontStyles_Click(object sender, RoutedEventArgs e)
        {
            // Set the editors font according to the MenuFlyoutItem selected
            MenuFlyoutItem item = (MenuFlyoutItem)sender;

            Windows.UI.Text.ParagraphStyle style = new Windows.UI.Text.ParagraphStyle();
            if (item.Text == "Heading1")
            {
                style = Windows.UI.Text.ParagraphStyle.Heading1;
            }
            else if (item.Text == "None")
            {
                style = Windows.UI.Text.ParagraphStyle.None;
            }
            else if (item.Text == "Normal")
            {
                style = Windows.UI.Text.ParagraphStyle.Normal;
            }
            else if (item.Text == "Undefined")
            {
                style = Windows.UI.Text.ParagraphStyle.Undefined;
            }
            editor.Document.Selection.ParagraphFormat.Style = style;
        }
Exemplo n.º 2
0
        int sumRGB;                                    // sum of the selected colors RGB
        //int pos, line, column;    // for detecting line and column numbers
        //int selectedFontSize = 0;
        //string filenamee;    // file opened inside of RTB
        public MainPage()
        {
            this.InitializeComponent();

            // Initialize MenuFlyouts on startup with the appropriate MenuFlyout object
            MenuFlyout mnuSize  = mnuFontSize;
            MenuFlyout mnuColor = mnuFontColor;

            // Fill Font Menu Flyout Items List
            string[] fonts = Microsoft.Graphics.Canvas.Text.CanvasTextFormat.GetSystemFontFamilies();
            // Sort fonts a->z
            Array.Sort(fonts, (x, y) => String.Compare(x.ToString(), y.ToString()));
            foreach (string font in fonts)
            {
                MenuFlyoutItem mnFont = new MenuFlyoutItem();
                mnFont.Text = font;
                mnuFontSelection.Items.Add(mnFont);
                mnFont.Click += MnFont_Click;
            }

            // Fill Font Size Menu Flyout Items List
            for (int i = 0; i < 90; i++)
            {
                MenuFlyoutItem mnFontSize = new MenuFlyoutItem();
                mnFontSize.Text = i.ToString();
                mnuSize.Items.Add(mnFontSize);
                mnFontSize.Click += MnFontSize_Click;
            }

            // FontColor list
            foreach (PropertyInfo prop in typeof(Colors).GetProperties())
            {
                if (prop.PropertyType.FullName == "Windows.UI.Color")
                {
                    colorList.Add(prop.Name);
                }
            }

            // Fill FontColor Menu Flyout Items List
            foreach (string color in colorList)
            {
                MenuFlyoutItem mnFontColor = new MenuFlyoutItem();
                mnFontColor.Text = color;
                mnuColor.Items.Add(mnFontColor);
                mnFontColor.Click += MnFontColor_Click;
            }

            // Fill BackColor for each color in the Font Color Menu Flyout
            for (int i = 0; i < mnuColor.Items.Count; i++)
            {
                // Create Color object
                Color selectedColor = new Color();
                selectedColor = (Color)typeof(Colors).GetProperty(colorList[i]).GetValue(selectedColor);

                // Set background color of menu items according to its color
                mnuColor.Items[i].Background = new SolidColorBrush(selectedColor);

                // Set the text color depending on if the barkground is darker or lighter
                // Create Color object
                Color col = Color.FromArgb(selectedColor.A, selectedColor.R, selectedColor.G, selectedColor.B);

                // 255,255,255 = White and 0,0,0 = Black
                // Max sum of RGB values is 765 -> (255 + 255 + 255)
                // Middle sum of RGB values is 382 -> (765/2)
                // Color is considered darker if its <= 382
                // Color is considered lighter if its > 382
                sumRGB = ConvertToRGB(col);                                           // get the color objects sum of the RGB value
                if (sumRGB <= MIDDLE)                                                 // Darker Background
                {
                    mnuColor.Items[i].Foreground = new SolidColorBrush(Colors.White); // Set to white text
                }
                else if (sumRGB > MIDDLE)                                             // Lighter Background
                {
                    mnuColor.Items[i].Foreground = new SolidColorBrush(Colors.Black); // Set to black text
                }
            }

            // Fill FontStyle MenuFlyoutItem List
            Windows.UI.Text.ParagraphStyle[] styles;
            styles    = new Windows.UI.Text.ParagraphStyle[4];
            styles[0] = Windows.UI.Text.ParagraphStyle.Heading1;
            styles[1] = Windows.UI.Text.ParagraphStyle.None;
            styles[2] = Windows.UI.Text.ParagraphStyle.Normal;
            styles[3] = Windows.UI.Text.ParagraphStyle.Undefined;
            for (int i = 0; i < styles.Count(); i++)
            {
                MenuFlyoutItem mnFontStyles = new MenuFlyoutItem();
                mnFontStyles.Text = styles[i].ToString();
                mnuFontStyles.Items.Add(mnFontStyles);
                mnFontStyles.Click += MnFontStyles_Click;
            }
        }