Пример #1
0
    protected void On_ColorAction_Activated(object sender, EventArgs e)
    {
        ColorSelectionDialog colorDlg = new ColorSelectionDialog("Select Color");

        colorDlg.SetDefaultSize(300, 220);
        //if click ok
        if (colorDlg.Run() == (int)ResponseType.Ok)
        {
            //get color
            Gdk.Color selectColor = colorDlg.ColorSelection.CurrentColor;

            //set color_tag
            color_tag.ForegroundGdk = selectColor;

            //if user selected some text
            //change selected text color
            //else change all text color
            TextIter start, end;
            if (TextView.Buffer.GetSelectionBounds(out start, out end))
            {
                TextView.Buffer.ApplyTag(color_tag, start, end);
            }
            else
            {
                TextView.ModifyText(StateType.Normal, selectColor);
            }
        }
        //destory window
        colorDlg.Destroy();
    }
        public static Gtk.Window Create()
        {
            HBox        options      = new HBox(false, 0);
            CheckButton check_button = null;

            window = new ColorSelectionDialog("Color selection dialog");
            window.ColorSelection.HasOpacityControl = true;
            window.ColorSelection.HasPalette        = true;

            window.SetDefaultSize(250, 200);
            window.ContentArea.PackStart(options, false, false, 0);
            window.ContentArea.BorderWidth = 10;

            check_button        = new CheckButton("Show Opacity");
            check_button.Active = true;
            options.PackStart(check_button, false, false, 0);
            check_button.Toggled += new EventHandler(Opacity_Callback);

            check_button        = new CheckButton("Show Palette");
            check_button.Active = true;
            options.PackEnd(check_button, false, false, 0);
            check_button.Toggled += new EventHandler(Palette_Callback);

            window.ColorSelection.ColorChanged += new EventHandler(Color_Changed);
            window.OkButton.Clicked            += new EventHandler(Color_Selection_OK);
            window.CancelButton.Clicked        += new EventHandler(Color_Selection_Cancel);

            options.ShowAll();

            return(window);
        }