<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # IronPython Mono Winforms 中的第一步 > 原文: [http://zetcode.com/tutorials/ironpythontutorial/firststeps/](http://zetcode.com/tutorials/ironpythontutorial/firststeps/) 在 IronPython Mono Winforms 教程的這一部分中,我們介紹 Winforms 編程庫中的一些基本程序。 ## 簡單 這是一個簡單的 Winforms 應用。 `simple.py` ```py #!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") from System.Windows.Forms import Application, Form class IForm(Form): def __init__(self): self.Text = 'Simple' self.Width = 250 self.Height = 200 self.CenterToScreen() Application.Run(IForm()) ``` 此代碼示例在屏幕上顯示一個小窗口。 ```py clr.AddReference("System.Windows.Forms") ``` 我們添加了 Winforms 庫的引用。 ```py class IForm(Form): ``` 在 Winforms 中,任何窗口或對話框都是`Form`。 該控件是一個基本容器,其目的是顯示其他子控件。 我們的類`IForm`繼承自表單。 這樣,它本身就成為一種形式。 ```py self.Text = 'Simple' self.Width = 250 self.Height = 200 ``` `Text`,`Width`和`Height`是表單的屬性。 更改這些屬性,我們將修改表單控件。 第一行在表單控件的標題欄中顯示文本`"Simple"`。 其他兩行將表單的大小設置為`250x200`像素。 ```py self.CenterToScreen() ``` 這種方法將我們的應用集中在屏幕上。 ```py Application.Run(IForm()) ``` 此行運行示例。 ![Simple](https://img.kancloud.cn/be/ef/beefe1a55e782a93c548f5f377cb822e_250x201.jpg) 圖:簡單 ## 圖標 Mono 在西班牙語中意為猴子。 如果我們不為應用提供圖標,則默認情況下,我們的頭是猴子。 下一個示例顯示如何更改此設置。 `icon.py` ```py #!/usr/bin/ipy import clr import sys clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form from System.Drawing import Icon class IForm(Form): def __init__(self): self.Text = 'Icon' self.Width = 250 self.Height = 200 try: self.Icon = Icon("web.ico") except Exception, e: print e.msg sys.exit(1) self.CenterToScreen() Application.Run(IForm()) ``` 該代碼示例在窗體的左上角顯示一個圖標。 表單的圖標是代表任務欄中表單的圖片以及為表單的控制框顯示的圖標。 ```py clr.AddReference("System.Drawing") ``` `Icon`對象來自`System.Drawing`模塊。 因此,我們必須添加引用。 ```py try: self.Icon = Icon("web.ico") except Exception, e: print e.msg sys.exit(1) ``` 最好將所有輸入輸出工作放在`try`和`except`關鍵字之間。 `web.ico`文件必須在當前工作目錄中可用。 這是我們執行應用的目錄(`ipy icon.py`)。 ![Icon](https://img.kancloud.cn/78/e9/78e914ffb8f9fc04b8a80d4bd7b0a4f1_250x201.jpg) 圖:圖標 ## 工具提示 工具提示是一個小的矩形彈出窗口,當用戶將指針放在控件上時,它會顯示控件目的的簡短說明。 `tooltips.py` ```py #!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form from System.Windows.Forms import Button, ToolTip from System.Drawing import Point, Size class IForm(Form): def __init__(self): self.Text = 'Tooltips' self.CenterToScreen() self.Size = Size(200, 150) tooltip = ToolTip() tooltip.SetToolTip(self, "This is a Form") button = Button() button.Parent = self button.Text = "Button" button.Location = Point(50, 70) tooltip.SetToolTip(button, "This is a Button") Application.Run(IForm()) ``` 我們的代碼示例為兩個控件創建一個工具提示。 `Button`控件和`Form`控件。 ```py tooltip = ToolTip() ``` 在這里,我們創建`ToolTip`控件。 此實例用于為兩個控件提供工具提示。 ```py tooltip.SetToolTip(self, "This is a Form") ``` 在這里,我們為表單設置工具提示。 ```py tooltip.SetToolTip(button, "This is a Button") ``` 這里是按鈕。 ```py button = Button() button.Parent = self button.Text = "Button" button.Location = Point(50, 70) ``` 注意`Button`控件的創建。 `Parent`屬性確定按鈕所在的容器。 `Text`屬性是按鈕的標簽。 `Location`屬性將按鈕放在表單上的`x = 30`,`y = 70px`坐標處。 ![Tooltips](https://img.kancloud.cn/82/c2/82c266959192927628a54c0d43e61994_250x201.jpg) 圖:工具提示 s ## 按鈕 我們的最后一個代碼示例顯示了一個有效的按鈕控件。 `button.py` ```py #!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form, Button from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = 'Button' self.CenterToScreen() self.Size = Size(200, 150) btn = Button() btn.Parent = self btn.Text = "Quit" btn.Location = Point(50, 50) btn.Click += self.OnClick btn.MouseEnter += self.OnEnter def OnClick(self, sender, args): self.Close() def OnEnter(self, sender, args): print "button entered" Application.Run(IForm()) ``` 所有 GUI 編程都是事件驅動的編程。 在我們的示例中,我們在表單容器上顯示了一個按鈕控件。 該按鈕將收聽兩個事件:`Click`和`MouseEnter`事件。 ```py btn.Click += self.OnClick ``` 此代碼行將事件處理器插入`Click`事件。 當我們單擊按鈕時,將調用`OnClick()`方法。 ```py btn.MouseEnter += self.OnEnter ``` 當我們使用鼠標指針進入按鈕區域時,將觸發`MouseEnter`事件。 在這種情況下,我們的代碼將調用`OnEnter()`方法。 ```py def OnClick(self, sender, args): self.Close() ``` 該方法關閉應用。 ```py def OnEnter(self, sender, args): print "button entered" ``` 當我們使用鼠標指針進入按鈕控制區域時,`"button entered"`文本將顯示在終端中。 IronPython Mono Winforms 教程的這一部分顯示了一些入門代碼示例。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看