Hi,
you're right lots of methods are deprecated, I don't know wich one to use.
I make my menus and menu bar with an xml string, and ActionEntry(s).
It is quite useful and well designed I think.

Here's an very simple example, I hope the code is correct (I'm not a good programmer I have to admit... but I'm improving!!).
You can compile the code and run it.

Hope this will be useful,

Regards,

Alex Grin


On 6/19/06, Nestor Alonso Torres <[EMAIL PROTECTED]> wrote:
Hi there!!!

I' ve tried to make a toolbar for an application, using gtk#, but I'
ve read in the documentation that AppendWidget is deprecated. I'm
using the following code:

               Toolbar t = new Toolbar ();
                Gtk.Button b1 = new Button(Stock.Add);

                t.AppendWidget (b1, "Add", "");

                b2 = new Button(Stock.Find);
                t.AppendWidget (b2, "Find", "");


                vbox.PackEnd(t, false, false, 10 );

I'd also like to make it looks "Windows like", I mean, no text in the
right side of the icon.

What's the correct way to do this?

Cheers,

Eng. Nestor Alonso Torres CM3NA
Linux User #349581
CUJAE, Havana, Cuba.
_______________________________________________
Gtk-sharp-list maillist  -   [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

using System;
using Gtk;
using System.Collections;

class View : Window {

  
   public VBox vbox=new VBox(false,4);
   public  ActionGroup actionGroup = null;
   public  UIManager uim = new UIManager();
   public  ActionEntry[] bookmarkEntries;
   public  ToggleActionEntry[] toggleEntries;
   public  ActionEntry[] entries;
		
   
    public View() :base("Example menu"){
    
        Add(vbox);
        Resize(700, 500);
        DeleteEvent += this.OnDelete;
        InitUiManager();
        vbox.PackStart (uim.GetWidget("/menubar"), false, true, 0);
		vbox.PackStart (uim.GetWidget("/toolbar"), false, true, 0);
        ShowAll();
   }
    
   private void InitUiManager(){
	   
	   //Basic entries
	   entries = new ActionEntry[] {
			//args : 
			//   1/ actionName (used in the xml string)
			//   2/ Stock.id
			//   3/ label
			//   4/ shortcut
			//   5/ tooltip
			//   6/ action
			new ActionEntry ("firstMenu","Menu", "_File", null,"", null),
			new ActionEntry ("cut", Stock.Cut, "C_ut", "<control>X","Cut to the clipboard", new EventHandler (this.OnCut)),
	        new ActionEntry ("quit", Stock.Quit, "Q_uit", "<control>Q","Quit the application",new EventHandler (this.OnQuit)),
   			new ActionEntry ("secondMenu","Edit", "_Edit", null,"", null),
		};
		
		//toggleEntries
		
		toggleEntries = new ToggleActionEntry[] {
		  //args : 
			//   1/ actionName (used in the xml string)
			//   2/ Stock.id
			//   3/ label
			//   4/ shortcut
			//   5/ tooltip
			//   6/ action
			//   7/ bool to indicate if the toggle button is checked (when creating the toolbar)
		  new ToggleActionEntry ("bold", Stock.Bold, "Bold font", "<control>B","Apply the bold font",new EventHandler (this.OnBold),true)
		};
         actionGroup = new ActionGroup ("TestActions");
		 actionGroup.Add (entries);
		 actionGroup.Add(toggleEntries);
		 
		 uim.InsertActionGroup (actionGroup, 0);
		 
		 // the name attribute of <toolbar> is used to retrieve the widget like uim.GetWidget("/toolbar")
		 string ui_info = 
			"  <menubar>\n" +
			"    <menu name=\"MenuFile\" action=\"firstMenu\" >\n" +
			"      <menuitem name=\"quit\" action=\"quit\" />\n" +
			"    </menu>\n" +
			"    <menu name=\"MenuEdit\" action=\"secondMenu\" >\n" +
            "      <menuitem name=\"Bold\" action=\"bold\" />\n" +
			"      <separator name=\"sep2\" />\n" +
			"      <menuitem name=\"cut\" action=\"cut\" />\n" +
			"    </menu>\n" +
			"  </menubar>\n" +
			"  <toolbar name=\"toolbar\">\n" +
			"    <toolitem name=\"cut\" action=\"cut\" />\n" +
            "    <toolitem name=\"Bold\" action=\"bold\" />\n" +
            "    <toolitem name=\"Quitter\" action=\"quit\" />\n" +
			"  </toolbar>\n";
  
		 uim.AddUiFromString (ui_info);	
	}
	
    public void OnDelete (object o, DeleteEventArgs e){
        Application.Quit ();
    } 
     
    public void OnQuit(object o, EventArgs args){
          Application.Quit ();
    } 
    
    public void OnCut(object o, EventArgs args){
        Console.WriteLine("cut cut cut");
    }
    
     public void OnBold(object o, EventArgs args){
        Console.WriteLine("bold bold bold");
    }
    
}

public class Runner {
    
    public static void Main() {
        Application.Init();
        View view=new View();
        Application.Run ();
    }
 }
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to