[Gtk-sharp-list] Gtk# help

aliencode at sapo.pt aliencode at sapo.pt
Tue Jan 22 09:26:50 EST 2008


Hi everybody

I need some help, i am creating an application using mono (obvious :P  
) and i need to create have a widget with background image and on top  
of it will be a table layout. After that i need to add this widget on  
the main window. I already solve the problem for the background image  
but when its loaded it fill all the main window background too. so  
what i would like to have is the new widget as a utility bar.

My code for the backgound that i want to attach to the main window

public partial class frmFretboard : Gtk.Window
	{


		public frmFretboard():
				base(Gtk.WindowType.Popup)
		{
			this.Build();

//			Gtk.Style wndStyle;
//			wndStyle = new Gtk.Style();
			this.Style.BgPixmap( StateType.Normal );
			try
			{
				Gdk.Pixbuf image = new Gdk.Pixbuf( "guitarfretboard.jpg" );
				Gdk.Pixmap pixmap, pixmap_mask;
				image.RenderPixmapAndMask( out pixmap, out pixmap_mask, 255 );
				int width  = image.Width;
				int height = image.Height;
				this.Style.SetBgPixmap(StateType.Normal,pixmap );
				this.SetSizeRequest(width,height);
				this.Resize(width,height);

			}
			catch(System.Exception e)
			{

				MessageBox msg = new MessageBox();

				msg.Show(e.Message);
				Application.Quit();
			}
		}


	}

The next code is the widget i created where the first will be attached  
  and then this one will be attached to the main window.
public partial class FretBoard : Gtk.Bin
	{
		private Widget fretboard;

		public FretBoard()
		{
			this.Build();
			Added += new AddedHandler (OnWidgetAdded);
			SizeRequested += new SizeRequestedHandler (OnSizeRequested);
           	SizeAllocated += new SizeAllocatedHandler (OnSizeAllocated);
//			fretboard = new frmFretboard();
			this.Add(new frmFretboard());

		}

		public void SetStringPressed( int pos_x, int pos_y )
		{

			//tblFretboard.Attach();
		}


		void OnWidgetAdded (object o, AddedArgs args)
		{
			fretboard = args.Widget;
		}


	    void OnSizeRequested (object o, SizeRequestedArgs args)
		{
			if (fretboard != null)
			{
                int width = args.Requisition.Width;
                int height = args.Requisition.Height;

                fretboard.GetSizeRequest (out width, out height);
                if (width == -1 || height == -1)
                     width = height = 80;
                SetSizeRequest (width , height );
           }

      	}

      //
      // Invoked to propagate our size
      //
      void OnSizeAllocated (object o, SizeAllocatedArgs args)
      {
           if (fretboard != null){
                Gdk.Rectangle mine = args.Allocation;
                Gdk.Rectangle his = mine;

//               his.X += pad;
//               his.Y += pad;
//               his.Width -= pad * 2;
//               his.Height -= pad * 2;
                fretboard.SizeAllocate (his);
           }
      }

Thanks in advance.


More information about the Gtk-sharp-list mailing list