Discussion:
[Gtk-sharp-list] Menu quit handler
Sascha Manns
2017-02-10 13:04:31 UTC
Permalink
Hello list,

i have defined a menu item "File/Quit" like so:

<object class="GtkMenuItem">
  <property name="visible">True</property>
  <property name="can_focus">False</property>
  <property name="label" translatable="yes">_Datei</property>
  <property name="use_underline">True</property>
  <child type="submenu">
    <object class="GtkMenu">
      <property name="visible">True</property>
      <property name="can_focus">False</property>
      <child>
        <object class="GtkImageMenuItem" id="menuQuit">
          <property name="label">gtk-quit</property>
          <property name="name">menuQuit</property>
          <property name="visible">True</property>
          <property name="can_focus">False</property>
          <property name="use_underline">True</property>
          <property name="use_stock">True</property>
          <signal name="activate" handler="OnMenuQuitActivate"
swapped="no"/>
        </object>
      </child>
    </object>
  </child>
</object>

How must be the "OnMenuQuitActivate" handler looks like, that it quits
the application?

I tried out:

protected void OnMenuQuitActivate(object sender, DeleteEventArgs a) {
    Application.Quit();
    a.RetVal = true;
}

But that doesn't work.

Greetings
Sascha
Baltasar García Perez-Schofield
2017-02-12 10:01:35 UTC
Permalink
Hi, Sascha,

Mmmm... that's not the signature for MenuItem's activation... your signal
handler seems to be more related to window deletion than to a menu item
activation.

Take a look here:
http://zetcode.com/gui/gtksharp/menus/

And here:
http://zetcode.com/gui/gtksharp/firststeps/

In short, your method should be:
==
protected void OnMenuQuitActivate(object sender, EventArgs a) {
Application.Quit();
}
==

Hope this helps,
-- Baltasar
Post by Sascha Manns
Hello list,
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Datei</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="menuQuit">
<property name="label">gtk-quit</property>
<property name="name">menuQuit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="OnMenuQuitActivate" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
How must be the "OnMenuQuitActivate" handler looks like, that it quits the
application?
protected void OnMenuQuitActivate(object sender, DeleteEventArgs a) {
Application.Quit();
a.RetVal = true;
}
But that doesn't work.
Greetings
Sascha
_______________________________________________
http://lists.dot.net/mailman/listinfo/gtk-sharp-list
Loading...