[MonoDevelop] make my own widget
Jeha
j-halverson at rr.em-net.ne.jp
Sat Oct 6 09:20:28 UTC 2012
You should be able to make any sort of GUI you would need with the
Monodevelop IDE. I have recently made a date pop-up widget like what you
seem to be requesting. To make this, I used the IDE to make one label and
one button, then linked the Button clicked event to my handler which will
pop up my calendar. Here is my source:
---------------------------------
using System;
using Gtk;
namespace AcornTrail3
{
[System.ComponentModel.ToolboxItem(true)]
public partial class DatePopup : Gtk.Bin
{
public delegate void DateChangedHandler(DateTime date);
public event DateChangedHandler DateChanged;
Gtk.Calendar calendar;
Gtk.Window popupmenu;
Gtk.EventBox eventbox;
DateTime datetime;
public DateTime Date
{
get { return datetime; }
set { datetime = value;
dateButton.Label = datetime.ToString ("yyyy/MM/dd");
if (this.DateChanged!=null) this.DateChanged(datetime);
}
}
public string Label {
get { return dateLabel.Text;}
set { dateLabel.Text = value;}
}
public DatePopup ()
{
this.Build ();
popupmenu = new Window(WindowType.Toplevel);
popupmenu.SkipPagerHint = true;
popupmenu.SkipTaskbarHint = true;
popupmenu.Decorated = false;
popupmenu.Modal = true;
popupmenu.KeepAbove = true;
eventbox = new EventBox();
Gtk.HBox menuhbox = new HBox();
calendar = new Calendar();
calendar.ButtonPressEvent += new
Gtk.ButtonPressEventHandler(calendarclick);
calendar.KeyPressEvent += new Gtk.KeyPressEventHandler(calendarkeypress);
calendar.FocusOutEvent += new Gtk.FocusOutEventHandler(calendarfocusout);
menuhbox.PackStart (calendar,true,true,0);
eventbox.Add (menuhbox);
popupmenu.Add (eventbox);
}
protected void OnDateButtonClicked (object sender, EventArgs e)
{
int x, y;
int height, xx, yy;
xx = (sender as Button).Allocation.X;
yy = (sender as Button).Allocation.Y;
height = (sender as Button).Allocation.Height;
this.GdkWindow.GetOrigin(out x, out y);
popupmenu.Move (x+xx,y+yy+height);
popupmenu.ShowAll ();
Gdk.Pointer.Grab (popupmenu.GdkWindow,true,Gdk.EventMask.ButtonPressMask
| Gdk.EventMask.FocusChangeMask,null,null,Gtk.Global.CurrentEventTime);
Gdk.Keyboard.Grab(popupmenu.GdkWindow, true,
Gtk.Global.CurrentEventTime);
Gtk.Grab.Add(popupmenu);
}
private void closepopup ()
{
Gtk.Grab.Remove (popupmenu);
Gdk.Keyboard.Ungrab (Gtk.Global.CurrentEventTime);
Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
popupmenu.HideAll ();
}
private void calendarclick (object o, Gtk.ButtonPressEventArgs args)
{
closepopup();
Date = calendar.GetDate();
}
private void calendarkeypress (object o, Gtk.KeyPressEventArgs args)
{
if (args.Event.Key == Gdk.Key.Escape || args.Event.Key == Gdk.Key.Return)
{
closepopup();
}
}
private void calendarfocusout (object o, Gtk.FocusOutEventArgs args)
{
closepopup();
}
}
}
--------------------
And here is the GUI source ( but really you should let the IDE make this for
you).
-------------------
// This file has been generated by the GUI designer. Do not modify.
namespace AcornTrail3
{
public partial class DatePopup
{
private global::Gtk.HBox hbox1;
private global::Gtk.Label dateLabel;
private global::Gtk.Button dateButton;
protected virtual void Build ()
{
global::Stetic.Gui.Initialize (this);
// Widget AcornTrail3.DatePopup
global::Stetic.BinContainer.Attach (this);
this.Name = "AcornTrail3.DatePopup";
// Container child AcornTrail3.DatePopup.Gtk.Container+ContainerChild
this.hbox1 = new global::Gtk.HBox ();
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.dateLabel = new global::Gtk.Label ();
this.dateLabel.Name = "dateLabel";
this.dateLabel.LabelProp = global::Mono.Unix.Catalog.GetString ("Date:");
this.hbox1.Add (this.dateLabel);
global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.hbox1
[this.dateLabel]));
w1.Position = 0;
w1.Expand = false;
w1.Fill = false;
// Container child hbox1.Gtk.Box+BoxChild
this.dateButton = new global::Gtk.Button ();
this.dateButton.CanFocus = true;
this.dateButton.Name = "dateButton";
this.dateButton.UseUnderline = true;
this.dateButton.Xalign = 0F;
this.dateButton.Label = global::Mono.Unix.Catalog.GetString
("GtkButton");
this.hbox1.Add (this.dateButton);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox1
[this.dateButton]));
w2.Position = 1;
this.Add (this.hbox1);
if ((this.Child != null)) {
this.Child.ShowAll ();
}
this.Hide ();
this.dateButton.Clicked += new global::System.EventHandler
(this.OnDateButtonClicked);
}
}
}
------------------------
--
View this message in context: http://mono.1490590.n4.nabble.com/make-my-own-widget-tp4656832p4656847.html
Sent from the Mono - MonoDevelop IDE mailing list archive at Nabble.com.
More information about the Monodevelop-list
mailing list