[Gtk-sharp-list] ColorSelectionDialog
Chris Howie
cdhowie at gmail.com
Mon Jun 15 21:28:42 EDT 2009
On Mon, Jun 15, 2009 at 8:52 PM, Darwin Reynoso<monouser at gmail.com> wrote:
> Hi,
> can someone please tell what's wrong with this code?
>
> [Task:File=/home/user/Projects/editor/editor/MainWindow.cs, Line=42,
> Column=25, Type=Error, Priority=Normal, Description=Cannot implicitly
> convert type `Gtk.ColorSelection' to `Gdk.Color'(CS0029)]
>
> void setColor()
> {
> colorDialog = new ColorSelectionDialog("select color");
>
> color = new Gdk.Color();
>
> if(colorDialog.Run()==(int)ResponseType.Ok)
> {
> color = colorDialog.ColorSelection;
> textview1.ModifyText(StateType.Normal,color);
> }
>
> }
The correct answer to the question is: "it's in the documentation, RTFM."
However, to help point you in the right direction,
ColorSelectionDialog.ColorSelection returns a GTK widget that holds
the Gdk.Color you are after.
Also, you are not properly destroying the dialog after you use it.
You should add a line right before the end of the method (outside of
the if block) that reads "colorDialog.Destroy();". If you are feeling
particularly paranoid about exceptions, you should wrap the block in a
try/finally, like so:
try {
// Your method code goes here
} finally {
if (colorDialog != null) {
colorDialog.Destroy();
colorDialog = null;
}
}
--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
More information about the Gtk-sharp-list
mailing list