コード例 #1
0
        private void ColorPickerPW_Closing(object sender, EventArgs e)
        {
            PWindow_ColorPicker pcl = (PWindow_ColorPicker)sender;

            if (pcl.OK)
            {
                if (pcl.DestroyColorB == false)
                {
                    ((Rectangle)pcl.obj).Fill = new SolidColorBrush(pcl.color);

                    if (pcl.obj == BackColor)
                    {
                        txt.Selection.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(pcl.color));
                    }
                    else
                    {
                        txt.Selection.ApplyPropertyValue(ForegroundProperty, new SolidColorBrush(pcl.color));
                    }
                }
                else
                {
                    txt.Selection.ApplyPropertyValue(TextElement.BackgroundProperty, null);
                }

                TextPointer textPointer1 = txt.Selection.Start;
                TextPointer textPointer2 = txt.Selection.End;
                txt.Selection.Select(txt.Document.ContentStart, txt.Document.ContentStart);

                Task.Factory.StartNew(() => Thread.Sleep(30))
                .ContinueWith((t) =>
                {
                    txt.Selection.Select(textPointer1, textPointer2);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
コード例 #2
0
        private void FButton_ColorPicker(object sender, MouseEventArgs e)
        {
            if (sender == FButton_CPickerB)
            {
                Point location = FButton_CPickerB.PointToScreen(new Point(0, 0));

                PWindow_ColorPicker pcl = new PWindow_ColorPicker(true);
                pcl.Left     = location.X;
                pcl.Top      = location.Y + FButton_CPickerB.Height;
                pcl.obj      = BackColor;
                pcl.Closing += ColorPickerPW_Closing;
                pcl.Show();
            }
            if (sender == FButton_CPickerF)
            {
                Point location = FButton_CPickerF.PointToScreen(new Point(0, 0));

                PWindow_ColorPicker pcl = new PWindow_ColorPicker();
                pcl.Left     = location.X;
                pcl.Top      = location.Y + FButton_CPickerF.Height;
                pcl.obj      = ForColor;
                pcl.Closing += ColorPickerPW_Closing;
                pcl.Show();
            }
        }