<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Mono Winforms 中的基本控件 II > 原文: [http://zetcode.com/tutorials/ironpythontutorial/controlsII/](http://zetcode.com/tutorials/ironpythontutorial/controlsII/) 在 IronPython Mono Winforms 教程的這一部分中,我們將繼續介紹基本的 Mono Winforms 控件。 ## `RadioButton` 與其他`RadioButton`控件配對時,`RadioButton`控件使用戶能夠從一組選項中選擇一個選項。 `GroupBox`控件用于將單選按鈕配對在一起。 `radiobutton.py` ```py #!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form, StatusBar from System.Windows.Forms import RadioButton, GroupBox from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = "RadioButton" self.Size = Size(240, 240) gb = GroupBox() gb.Text = "Sex" gb.Size = Size(120, 110) gb.Location = Point(20, 20) gb.Parent = self male = RadioButton() male.Text = "Male" male.Parent = gb male.Location = Point(10, 30) male.CheckedChanged += self.OnChanged female = RadioButton() female.Text = "Female" female.Parent = gb female.Location = Point(10, 60) female.CheckedChanged += self.OnChanged self.statusbar = StatusBar() self.statusbar.Parent = self self.CenterToScreen() def OnChanged(self, sender, event): if sender.Checked: self.statusbar.Text = sender.Text Application.Run(IForm()) ``` 在我們的示例中,我們在一個組框中顯示了兩個單選按鈕。 一次只能選擇一個選項。 選項值顯示在狀態欄中。 ```py gb = GroupBox() gb.Text = "Sex" ``` `GroupBox`控件用于將單選按鈕組合在一起。 這樣,我們一次只能選擇一個單選按鈕控件。 ```py male = RadioButton() male.Text = "Male" male.Parent = gb ``` 創建帶有文本`"Male"`的`RadioButton`控件。 它的父級是組框控件。 ```py def OnChanged(self, sender, event): if sender.Checked: self.statusbar.Text = sender.Text ``` `OnChanged()`方法將當前所選單選按鈕的文本設置為狀態欄控件。 ![RadioButton](https://img.kancloud.cn/e9/3f/e93f65a48535a2e2ac676d911c3ab711_240x241.jpg) 圖:`RadioButton` ## `MonthCalendar` 在下一個示例中,我們將顯示`MonthCalendar`控件。 `MonthCalendar`控件允許用戶使用視覺顯示選擇日期。 `monthcalendar.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 Label, MonthCalendar from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = 'MonthCalendar' self.Size = Size(240, 240) calendar = MonthCalendar() calendar.Parent = self calendar.Location = Point(20, 20) calendar.DateSelected += self.OnSelected self.date = Label() self.date.Location = Point(30, 180) self.date.Parent = self dt = calendar.SelectionStart self.date.Text = str(dt.Month) + "/" + str(dt.Day) + "/" + str(dt.Year) self.CenterToScreen() def OnSelected(self, sender, event): dt = sender.SelectionStart self.date.Text = str(dt.Month) + "/" + str(dt.Day) + "/" + str(dt.Year) Application.Run(IForm()) ``` 在示例中,我們顯示了`MonthCalendar`和`Label`。 ```py calendar = MonthCalendar() ... self.date = Label() ``` 我們有兩個控件。 一個`MonthCalendar`和一個`Label`。 后者顯示當前選擇的日期。 ```py def OnSelected(self, sender, event): dt = sender.SelectionStart self.date.Text = str(dt.Month) + "/" + str(dt.Day) + "/" + str(dt.Year) ``` 當我們從`MonthCalendar`中選擇一個日期時,就會調用`OnSelected()`方法。 `SelectionStart`屬性獲取所選日期范圍的開始日期。 ![MonthCalendar](https://img.kancloud.cn/62/20/6220e017d0d4d0f18037eb11929def9e_240x241.jpg) 圖:`MonthCalendar` ## `TextBox` `TextBox`控件用于顯示或接受某些文本。 文本可以是單行或多行。 此控件還可以進行密碼屏蔽。 `textbox.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 Label, TextBox from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = 'TextBox' self.text = Label() self.text.Parent = self self.text.Text = "..." self.text.AutoSize = True self.text.Location = Point(60, 40) tbox = TextBox() tbox.Parent = self tbox.Location = Point(60, 100) tbox.KeyUp += self.OnKeyUp self.Size = Size(250, 200) self.CenterToScreen() def OnKeyUp(self, sender, event): self.text.Text = sender.Text Application.Run(IForm()) ``` 本示例顯示一個文本框和一個標簽。 我們在文本框中鍵入的文本將立即顯示在標簽控件中。 ```py self.text = Label() ... self.text.AutoSize = True ``` `Label`控件已創建。 `AutoSize`屬性確保`Label`增長以顯示文本。 ```py tbox = TextBox() ... tbox.KeyUp += self.OnKeyUp ``` 我們將`KeyUp`事件插入到`TextBox`控件中。 釋放按鍵時,將調用`OnKeyUp()`方法。 ```py def OnKeyUp(self, sender, event): self.text.Text = sender.Text ``` 在`OnKeyUp()`方法中,我們使用文本框控件中的文本更新了標簽控件。 ![TextBox](https://img.kancloud.cn/70/8e/708e25952ac77d838f07c6b8f166e77c_250x201.jpg) 圖:`TextBox` ## `PictureBox` `PictureBox`控件用于在表單上顯示圖片。 `picturebox.py` ```py #!/usr/bin/ipy import sys import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form, PictureBox from System.Drawing import Size, Point, Bitmap class IForm(Form): def __init__(self): self.Text = 'PictureBox' try: castle = Bitmap('redrock.png') except Exception, e: print 'Cannot read image file' print e.msg sys.exit(1) pb = PictureBox() pb.Parent = self pb.Size = Size(castle.Width, castle.Height) pb.Location = Point(2, 2) pb.Image = castle self.Size = Size(castle.Width, castle.Height) self.CenterToScreen() Application.Run(IForm()) ``` 該示例顯示了表單上的 png 圖像。 ```py try: castle = Bitmap('redrock.png') except Exception, e: print 'Cannot read image file' print e.msg sys.exit(1) ``` 我們從當前工作目錄中獲得一個位圖。 ```py pb = PictureBox() ``` `PictureBox`控件已創建。 ```py pb.Image = castle ``` `Image`屬性指向我們創建的位圖。 ```py self.Size = Size(castle.Width, castle.Height) ``` 窗體的大小等于位圖的大小。 ![PictureBox](https://img.kancloud.cn/55/92/5592eb37c25209e2dd7f64f0c6a2c436_450x254.jpg) 圖:`PictureBox` 我們已經完成了 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>

                              哎呀哎呀视频在线观看