[Gtk-sharp-list] Cannot constrain resize of contained widget, why?

Michael Hutchinson m.j.hutchinson at gmail.com
Mon Apr 20 14:24:02 EDT 2009


On Mon, Apr 20, 2009 at 11:54 AM, simozzer <SimonMoscrop at hotmail.com> wrote:
>
> Hi folks,
>
> I am trying to build a (very) simple app using mono and Gtk-sharp which has
> the following document outline:
>
> MainWindow
>    hpaned1
>        GtkScrolledWindow
>            textview1
>        GtkScrolledWindow1
>            textview2
>
> This Works:
> =========
> To prevent the user from resizing the main form to make it too small i have
> hooked into the OnSizeRequested event. When I do this the event is called
> and I can intercept the resize. (So far so good)

On a Gtk.Window, there's a much easier way to do this. Just set
AllowShrink = false.

>
> This does not work:
> ==============
> I would also like to prevent the user from resizing the left textview
> (textview1) - specifically I do not want the user to make this area too
> small. To intercept the resize of the textview I try hooking some code up to
> the textview1SizeRequested event. When I do this my resize handling code is
> never called. Can anyone tell me why this is and what I need to do to get

GTK uses events internally for many things, and the textview widget is
actually handling the SizeRequested event already. By setting the
return value on the event args object, it marks the event as
"handled", thereby stopping it from getting propagated to the other
event handlers, i.e. yours.

Use the [GLib.ConnectBefore] attribute on your event handler. This
will ensure that it's places *before* the built-in handler. You can
then set args.Retval = true (or is it false?) to stop the event from
propagating to the built-in handler.

Although counter-intuitive to C#/.NET users, this feature can be very
useful when you want to override the built-in handlers.

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Gtk-sharp-list mailing list