[Gtk-sharp-list] Reloading Option Menu Do Not Work
Jorge De Gante
jdegante@linuxware.com.mx
14 Mar 2003 14:28:24 -0600
This code doesn't work as expected, I think.
namespace GtkSamples {
using Gtk;
using Gdk;
using GtkSharp;
using System;
public class HelloWorld {
static OptionMenu optionmenu;
static HBox hbox;
public static int Main (string[] args)
{
Application.Init ();
hbox = new HBox(true, 2);
Gtk.Window win = new Gtk.Window ("Gtk# Hello
World");
win.DeleteEvent += new DeleteEventHandler
(Window_Delete);
optionmenu = new OptionMenu();
Menu menu = new Menu ();
for (int i = 0; i < 10; i++)
{
MenuItem menu_item = new MenuItem
("Otcion " + i.ToString());
menu.Append (menu_item);
Console.WriteLine("Loading Option " +
i.ToString());
}
optionmenu.Menu = menu;
hbox.PackStart(optionmenu);
Button btn = new Button ("Reload Options");
btn.Clicked += new EventHandler (btn_click);
hbox.PackStart(btn);
win.Add(hbox);
win.ShowAll ();
Application.Run ();
return 0;
}
static void btn_click (object obj, EventArgs args)
{
Console.WriteLine ("Button Clicked");
hbox.Remove(optionmenu);
optionmenu = new OptionMenu();
Menu menu = new Menu ();
for (int i = 10; i < 20; i++)
{
MenuItem menu_item = new MenuItem
("Option " + i.ToString());
menu.Append (menu_item);
Console.WriteLine("Reloading Option " +
i.ToString());
}
optionmenu.Menu = menu;
hbox.PackStart(optionmenu);
optionmenu.Show();
}
static void Window_Delete (object obj, DeleteEventArgs
args)
{
SignalArgs sa = (SignalArgs) args;
Application.Quit ();
sa.RetVal = true;
}
}
}
Any ideas?
I need to dynamically reload option menus in my App.
How can I do it?
I have mono 2.0 gtk-sharp 7.0 on RH 8.0
Thanks in advance.
--
Jorge De Gante Tellez
jdegante@linuxware.com.mx
LinuxWare S.A. de C.V.
http://www.linuxware.com.mx
Tel. 26-03-15-15 26-03-15-16 26-03-15-17
Fax 26-03-15-18