简体   繁体   English

在MonoDevelop和GTKSharp中使用小部件

[英]Using widgets in MonoDevelop and GTKSharp

I switched from using VirtualStudio Express 2010 and I am trying to work with MonoDevelop and GTKSharp. 我转而使用VirtualStudio Express 2010,我正在尝试使用MonoDevelop和GTKSharp。 Now. 现在。 I am trying to switch to new editor software but it seems much different than VisualStudio. 我正在尝试切换到新的编辑器软件,但它似乎与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. 例如,当我在VisualStudio中创建一个按钮然后双击该项时,我会自动获取表示该表单中项目的代码。 And here is the problem, how do I create events for buttons and comboboxes in MonoDevelop? 这就是问题,如何在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. 首先,我想弄清楚如何使用ComboBox和按钮,这将允许我在ComboBox中选择3个选项之一,然后在按钮事件下我想根据已选择的项目触发3个独立窗口中的1个。

Please provide me some easy examples how to work with MonoDevelop or else I will need to switch back to Windows OS :( 请提供一些如何使用MonoDevelop的简单示例,否则我将需要切换回Windows操作系统:(

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: 所以,如果GTK#允许我到目前为止:

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. 创建一个新的C#GTK项目。

Open up the "MainWindow.cs" and at the bottom right of the window click the "Designer" button to go into designer mode. 打开“MainWindow.cs”,在窗口右下角单击“Designer”按钮进入设计器模式。

Next open up the hidden toolBox window at the right of the MonoDev window. 接下来打开MonoDev窗口右侧的隐藏工具箱窗口。 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. 现在再次访问您的SourceCode。 In the constructor write:: 在构造函数中写::

button1.Clicked += button1_Click;

Then make the new Click method. 然后制作新的Click方法。

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. 在Gtk中,概念名称稍有变化,当一个与windows窗体中的控件相同的窗口小部件,只是不同的名称,它会发出一个“信号”,那么你要做的就是“处理”那个信号。相当于在Windows窗体中捕获事件。

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. 您可以在monodevelop中选择您的小部件,然后转到该小部件的属性窗格,在那里您将看到一个名为“signals”的选项卡,其中包含小部件专门发出的信号列表,从而允许您在小部件会像被点击一样。 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!! 希望能帮助到你!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM