<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Mono Winforms 中的基本控件 > 原文: [http://zetcode.com/tutorials/ironpythontutorial/controls/](http://zetcode.com/tutorials/ironpythontutorial/controls/) IronPython Mono Winforms 編程教程的這一部分將介紹基本控件。 Winforms 控件是應用的基本構建塊。 Winforms 具有廣泛的各種控件。 按鈕,復選框,軌跡欄,標簽等。程序員完成工作所需的一切。 在本教程的這一部分中,我們將描述幾個有用的控件。 ## `Label` `Label`是用于顯示文本或圖像的簡單控件。 它沒有得到關注。 `label.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, Label from System.Drawing import Size, Point, Font text = """Meet you downstairs in the bar and heard Your rolled up sleeves and your skull t-shirt You say why did you do it with him today? And sniffed me out like I was tanqueray Cause you're my fella, my guy Hand me your stella and fly By the time I'm out the door You tear me down like roger moore I cheated myself Like I knew I would I told ya, I was trouble You know that I'm no good Upstairs in bed, with my ex boy He's in a place, but I cant get joy Thinking of you in the final throws, this is when my buzzer goes""" class IForm(Form): def __init__(self): self.Text = "You know I'm No Good" font = Font("Serif", 10) lyrics = Label() lyrics.Parent = self lyrics.Text = text lyrics.Font = font lyrics.Location = Point(10, 10) lyrics.Size = Size(290, 290) self.CenterToScreen() Application.Run(IForm()) ``` 在我們的示例中,我們在表單上顯示了一些歌詞。 ```py lyrics = Label() ``` `Label`控件已創建。 ```py text = """Meet you downstairs in the bar and heard ... """ ``` 這是我們的文字。 ```py font = Font("Serif", 10) ... lyrics.Font = font ``` 標簽文本的字體設置為 10px Serif。 ![Label](https://img.kancloud.cn/59/b9/59b9cd58672c7bd0860091fdada7c9e2_300x301.jpg) 圖:`Label` ## `CheckBox` `CheckBox`是具有兩個狀態的控件:開和關。 它是帶有標簽或圖像的盒子。 如果選中`CheckBox`,則在方框中用勾號表示。 `CheckBox`可用于在啟動時顯示或隱藏啟動畫面,切換工具欄的可見性等。 `checkbox.py` ```py #!/usr/bin/ipy import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form, CheckBox from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = "CheckBox" self.Size = Size(220, 170) cb = CheckBox() cb.Parent = self cb.Location = Point(30, 30) cb.Text = "Show Title" cb.Checked = True cb.CheckedChanged += self.OnChanged self.CenterToScreen() def OnChanged(self, sender, event): if sender.Checked: self.Text = "CheckBox" else: self.Text = "" Application.Run(IForm()) ``` 我們的代碼示例根據窗口的狀態顯示或隱藏窗口的標題。 ```py cb = CheckBox() ``` `CheckBox`控件已創建。 ```py cb.Text = "Show Title" cb.Checked = True ``` 當應用啟動時,我們顯示標題。 然后將`CheckBox`控件設置為選中狀態。 ```py cb.CheckedChanged += self.OnChanged ``` 當我們單擊`CheckBox`控件時,將觸發`CheckedChanged`事件。 ```py if sender.Checked: self.Text = "CheckBox" else: self.Text = "" ``` 在這里,我們切換窗口的標題。 ![CheckBox](https://img.kancloud.cn/9c/03/9c03fff56b27f629944c297bbd1a33ed_220x171.jpg) 圖:`CheckBox` ## `TrackBar` `TrackBar`是一個組件,使用戶可以通過在有限的間隔內滑動旋鈕來以圖形方式選擇一個值。 我們的示例將顯示音量控制。 `trackbar.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.Windows.Forms import TrackBar, TickStyle from System.Drawing import Size, Point, Bitmap class IForm(Form): def __init__(self): self.Text = 'TrackBar' self.Size = Size(260, 190) tb = TrackBar() tb.Parent = self tb.Size = Size(150, 30) tb.Location = Point(30, 50) tb.TickStyle = TickStyle.None tb.SetRange(0, 100) tb.ValueChanged += self.OnChanged self.LoadImages() self.pb = PictureBox() self.pb.Parent = self self.pb.Location = Point(210, 50) self.pb.Image = self.mutep self.CenterToScreen() def LoadImages(self): try: self.mutep = Bitmap("mute.png") self.minp = Bitmap("min.png") self.medp = Bitmap("med.png") self.maxp = Bitmap("max.png") except Exception, e: print "Error reading images" print e.msg sys.exit(1) def OnChanged(self, sender, event): val = sender.Value if val == 0: self.pb.Image = self.mutep elif val > 0 and val <= 30: self.pb.Image = self.minp elif val > 30 and val < 80: self.pb.Image = self.medp else: self.pb.Image = self.maxp Application.Run(IForm()) ``` 在代碼示例中,我們顯示了`TrackBar`和`PictureBox`。 通過拖動軌跡欄,我們可以在`PictureBox`控件上更改圖像。 ```py tb = TrackBar() ``` `TrackBar`控件已創建。 ```py tb.TickStyle = TickStyle.None ``` 我們對此`TrackBar`沒有顯示任何報價。 ```py self.pb = PictureBox() ... self.pb.Image = self.mutep ``` `PictureBox`控件已創建。 它用于顯示圖像。 開始時,它會顯示靜音圖像。 ```py self.mutep = Bitmap("mute.png") self.minp = Bitmap("min.png") self.medp = Bitmap("med.png") self.maxp = Bitmap("max.png") ``` 在這里,我們將創建四個將要使用的圖像。 ```py val = sender.Value if val == 0: self.pb.Image = self.mutep elif val > 0 and val <= 30: self.pb.Image = self.minp elif val > 30 and val < 80: self.pb.Image = self.medp else: self.pb.Image = self.maxp ``` 我們確定`TrackBar`的值。 根據其值,我們更新`PictureBox`控件。 ![TrackBar](https://img.kancloud.cn/9a/c8/9ac8d88ed2415cfe24d2d90453bcfa6f_260x191.jpg) 圖:`TrackBar` ## `ComboBox` `ComboBox`是一個組合了按鈕或可編輯字段和下拉列表的控件。 用戶可以從下拉列表中選擇一個值,該列表應用戶的要求出現。 如果使組合框可編輯,則組合框將包含一個可編輯字段,用戶可以在其中輸入值。 `combobox.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 ComboBox, Label from System.Drawing import Size, Point class IForm(Form): def __init__(self): self.Text = "ComboBox" self.Size = Size(240, 240) cb = ComboBox() cb.Parent = self cb.Location = Point(50, 30) cb.Items.AddRange(("Ubuntu", "Mandriva", "Red Hat", "Fedora", "Gentoo")) cb.SelectionChangeCommitted += self.OnChanged self.label = Label() self.label.Location = Point(50, 140) self.label.Parent = self self.label.Text = "..." self.CenterToScreen() def OnChanged(self, sender, event): self.label.Text = sender.Text Application.Run(IForm()) ``` 我們的代碼編程示例顯示了一個包含五個項目的組合框。 所選項目顯示在標簽控件中。 ```py cb = ComboBox() ``` `ComboBox`控件已創建。 ```py cb.Items.AddRange(("Ubuntu", "Mandriva", "Red Hat", "Fedora", "Gentoo")) ``` `ComboBox`控件中充滿了項目。 ```py cb.SelectionChangeCommitted += self.OnChanged ``` 如果我們從組合框中選擇一個項目,則會觸發`SelectionChangeCommitted`事件。 ```py def OnChanged(self, sender, event): self.label.Text = sender.Text ``` 在這里,將從組合框中選擇的文本復制到標簽。 ![ComboBox](https://img.kancloud.cn/de/c5/dec54b9d7a99aee63e1d0fa9dd974c23_240x241.jpg) 圖:`ComboBox` 我們已經完成了 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>

                              哎呀哎呀视频在线观看