protected void OnButtonUndelineColorClicked(object sender, EventArgs e) { ColorSelectionDialog dlg_color = new ColorSelectionDialog("Select color"); dlg_color.Response += delegate(object o, ResponseArgs resp) { if (resp.ResponseId == ResponseType.Ok) { underline_color_selected = dlg_color.ColorSelection.CurrentColor; string rgb = underline_color_selected.ToString(); ApplyTextTags(textviewDemoText.Buffer, "underlinecolor:" + rgb); } if (resp.ResponseId == ResponseType.Cancel) { } if (resp.ResponseId == ResponseType.Close) { } }; dlg_color.Run(); dlg_color.Destroy(); return; }
/// <summary> /// Converts Gdk.Color to hex RGB hash string using ToString() and some custom parsing to alleviate /// GTK# 2.12 limitation of ToString() result being unparsable with Parse(). /// </summary> /// <returns>The hex RGB hash string.</returns> /// <param name="color">Color as Gdk.Color</param> public static string GetHexRgbHashStringFromGdkColor(Gdk.Color color) { // In gtk-sharp 2.12 the result of ToString() is not parsable with Parse(), need to pre-process. // It looks like this: "rgb:rrrr/gggg/bbbb", we want "#rrrrggggbbbb". char[] delim_chars = { ':', '/' }; // First - split the string to pieces string[] color_selected_str_parts = color.ToString().Split(delim_chars); // Replace "rgb" with "#" color_selected_str_parts[0] = "#"; // Assemble it all back together string color_selected_str = string.Join(null, color_selected_str_parts); return(color_selected_str); }
static string ColorToString(Gdk.Color color) { return(color.ToString()); }