[Gtk-sharp-list] How to hide a widget from a glade file?

Miguel 26031@t-link.de
Tue, 01 Jun 2004 23:52:43 +0200


Hi,

my Intention is to make a app, which can "change" widgets per button
press.
To get that working I choosed two frame container and added a button
into each. If you press button1 it hides itself and button2 involves the
area from button1. If you press now button2, button3 rises on the area
which button1 was further. And so on.
This is only a simple example and works perfekt with self coded Gtk#.

//Source_beginn

// 1 Horizontal Box, 2 Button's, hide example

using Gtk;
using GtkSharp;
using System;

public class MoreWidget
{
	//Def Widgets globally
	Window win;
	HBox hbox1;
	Button button1;
	Button button2;
	Button button3;
	Frame frame1;
	Frame frame2;
	Frame frame3;

public static void Main(string[] args)
{
	new MoreWidget();

}


public MoreWidget()	
{	
	
	Application.Init();
	//Create Main Window
	win = new Window("MoreWidget1");
	win.SetDefaultSize(200,250);
	win.DeleteEvent += new DeleteEventHandler(delete_win);
	//Create 2 frames
	frame1 = new Frame();
	frame2 = new Frame();
	// Create 1 HBox
	hbox1 = new HBox(false,1);
	// Create 3 Buttons + EventHandler
	button1 = new Button("Button 1");
	button1.Clicked += new EventHandler(button1_clicked);
	button2 = new Button("Button 2");
	button2.Clicked += new EventHandler(button2_clicked);
	button3 = new Button("Button 3");
	button3.Clicked += new EventHandler(button3_clicked);
	//Add button1 and button2 to frame1 and frame2
	frame1.Add(button1);
	frame2.Add(button2);
	//Add the frames to the hbox
	hbox1.Add(frame1);
	hbox1.Add(frame2);
	//Add hbox1 Mainwindow
	win.Add(hbox1);
	win.ShowAll();
	
	Application.Run();
}

	//Event Handler
	void delete_win(object o, DeleteEventArgs args)
	{
		Application.Quit();
	}
	void button1_clicked(object o, EventArgs args)
	{
		frame1.Hide();
		frame1.Remove(button1);
		frame1.Add(button3);
		hbox1.Add(frame1);
	}
	
	void button2_clicked(object o, EventArgs args)
	{
		frame1.Show();
		win.ShowAll();
	}
	
	void button3_clicked(object o, EventArgs args)
	{
		frame1.Hide();
		frame1.Remove(button3);
		frame1.Add(button1);
		hbox1.Add(frame1);
	}


}
//Source_End


But I don't get that working with glade.
Here's my suggestion. But nothing happens.
Does somebody know how to handle it?

//Source_Beginn
using System;
  	using Gtk;
	using Glade;
	using GtkSharp;


public class MoreWidgets_Glade
{
	bool debug = true;
	// Define the widgets
	[Glade.Widget]   
	Button button1;
	Button button2;
	Frame frame1;
	Frame frame2;
	
public MoreWidgets_Glade()
{
	// Initial the Application
	Application.Init();
	//make Instances from frame
	// if you leave this out, you get null reference errors 
	frame1 = new Frame();
	frame2 = new Frame();
	//parse the .glade file
	Glade.XML gxml = new Glade.XML ("project6.glade", "window1", null);
	gxml.Autoconnect (this);
	//run the Application
	Application.Run();
}
	//Signal Handler
	void on_button1_clicked(object o, EventArgs args)
		{
			if(debug)Console.WriteLine("Button1 clicked");
			frame1.Hide();
			}
	void on_button2_clicked(object o, EventArgs args)
		{
			if(debug)Console.WriteLine("Button2 clicked");
			frame1.Show();
		}

public static void Main(string[] args)
{
	new MoreWidgets_Glade();
}
}
//Source_End


Thanks in advance

Michael