开发者

Using widgets in MonoDevelop and GTKSharp

I switched from using VirtualStudio Express 2010 and I am trying to work with MonoDevelop and GTKSharp. Now. I am trying to switch to new editor s开发者_运维百科oftware but it seems much different than VisualStudio.

What I am trying to do is basically to use widgets in this editor. For example when I am creating a button in VisualStudio and then double click the item then I am automatically getting the piece of code representing the item in the form. And here is the problem, how do I create events for buttons and comboboxes in MonoDevelop? I was looking through Internet examples for two days now and I can not figure out how to do it. The examples are not clear enough.

What I am trying to create? First I am trying to figure out how to use ComboBox and button which will allow me to choose one of 3 options in ComboBox and then under button event I want to fire 1 of 3 separate windows depending on which item has been picked.

Please provide me some easy examples how to work with MonoDevelop or else I will need to switch back to Windows OS :(

Please help!

// edit //

Lets say I got time on my hands and I am really interested in it. So if GTK# allow me so far:

public MainWindow () : base(Gtk.WindowType.Toplevel)
{
    Build ();
    button1.Clicked += button1_Click;
    combobox1.SelectionGet += comboBox1_Selection; << is this correct?
}


private void button1_Click(object s, EventArgs e)
{
}

private void comboBox1_Selection (object s, EventArgs e)
{
    switch (combobox1.SelectedIndex)
    {
        case 0:
            window1.Show();
            break;
        case 1:
            window2.Show();
            break;
        case 2:
            window3.Show();
            break;
    }
}

But I feel like I am more lost than I was earlier.


Create a new C# GTK project.

Open up the "MainWindow.cs" and at the bottom right of the window click the "Designer" button to go into designer mode.

Next open up the hidden toolBox window at the right of the MonoDev window. Drag out a "Fixed" Container on the main windows canvas. This is required to put Buttons and stuff on your window.

Now drag a button on the Fixed container. To move the button around click on the little white box above the button when selected.

Now go to your SourceCode again. In the constructor write::

button1.Clicked += button1_Click;

Then make the new Click method.

private void button1_Click(object s, EventArgs e)
{

}


You don't need to add the handlers manually...

In Gtk the concept names changes a little, when a widget which is the same as a control in windows forms, just different name, does something it emits a "signal" then what you have to do is to "handle" that signal which would be the equivalent to catch the event in windows forms.

You can just select your widget in monodevelop and then go to the properties pane of that widget, there you will see a tab called "signals", this has the list of the signals that the widget specifically emits, thus allowing you to code actions when the widget does something like being clicked. Once there just double click in the signal you want to handle, for example, for a button, double click on the "Released" signal which is the signal emitted by the button when you click on it and release it.

I'm attaching a screenshot so you can get the picture. Hope it helps!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜