C#windows编程:控件

Image控件:显示一张图片,source:指定图片位置。Stretch:图片的显示方式 None不会调整大小,Fill拉伸,Uniform保持宽高比,                UniformFill保持宽高比的同时填充区域

           //              图片位置                                  填充方式                       大小

  1. <Image Source=".\Images\xx.png" Stretch="UniformToFill"  Width="16" Height="16" />

Label控件:显示文本信息

           //(属性) 名字,                 显示文本                  水平布局方式             边距        Grid控件 显示的位置

  1.  <Label x:Name="label" Content="Players" HorizontalAlignment="Left" Margin="10,5,0,0" Grid.Row="2"
  2.  //垂直布局方式                                              前景色                    字体
  3. VerticalAlignment="Top" Foreground="black" FontFamily="Times New Roman"  />

TextBlock控件:可以显示多行文本,与ScrollViewer配合使用

             //                 显示的文本                                                                                            边距                        

  1.  <TextBlock Text="Visual C# 6 for Windows. You can Press at http://www.baidu.com." Margin="0, 10,0,0" Padding="20,0,0,0"
  2.  //     自动换行                           水平显示的布局              垂直布局                                          大小
  3. TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Height="39"/>

Button控件:按钮,点击

          //  名字           显示文本              Canvas布局                                         大小         点击事件方法

  1. <Button Name="ok" Content="_OK" Canvas.Right="12" Canvas.Bottom="10" Width="75" Click="Button_Click"/>

TextBox控件:可以显示文本,也可以输入文本信息

//                            名字                                          水平布局                                大小              边距                           Grid的第二行

  1.  <TextBox x:Name="newPlayerTextBox" HorizontalAlignment="Left" Height="23" Margin="252,31,0,0" Grid.Row="2"
  2. //自动换行                       垂直布局                          大小
  3. TextWrapping="Wrap" VerticalAlignment="Top" Width="166"/>

CheckBox控件:可以显示一个开关选项,单选框

        //                      显示的文本                 水平布局                              边距           垂直布局

  1. <CheckBox Content="computer" HorizontalAlignment="Left" Margin="11,33,0,0" VerticalAlignment="Top"
  2. //名字                         是否选择             绑定的数据
  3. Name="playCheck" IsChecked="{Binding Path=PlayAgainstComputer}"/>

RadioButton控件:可以让用户从多个RadioButton的选项中选择一个(单选)

      //三个RadioButton选项,一次只能选择其中一个选项

      //          选项显示的内容     水平布局                             边距                         垂直布局                                       

  1.             <RadioButton Content="Dumb" HorizontalAlignment="Left" Margin="37,41,0,0" VerticalAlignment="Top"
  2. //名字                                         选中的值
  3. Name="dumbAIRadioButton" Checked="dumbAIRadioButton_Checked"/>
  4.             <RadioButton Content="Good" HorizontalAlignment="Left" Margin="37,62,0,0" VerticalAlignment="Top" Name="goodAIRadioButton" Checked="goodAIRadioButton_Checked"/>
  5.             <RadioButton Content="Cheats" HorizontalAlignment="Left" Margin="37,83,0,0" VerticalAlignment="Top" Name="cheatingAIRadioButton" Checked="cheatingAIRadioButton_Checked"/>
  6.  

ConboBox控件:包含多个选项的下拉列表

            //   水平布局                                 边距                               垂直布局                         大小        

  1.  <ComboBox HorizontalAlignment="Left" Margin="196,58,0,0" VerticalAlignment="Top" Width="86"
  2. //名字                                                         选项的内容(绑定的数据)
  3. Name="numberOfPlayersComboBox" ItemsSource="{Binding Source={StaticResource numberOfPlayersData}}"
  4. //选项值                 绑定的数据
  5. SelectedValue="{Binding Path=NumberOfPlayers}" >
  6.        //选项内容(不使用绑定数据)
  7.        <ComboBoxItem>value</ComboBoxItem>
  8.        <ComboBoxItem>val</ComboBoxItem>
  9. </ComboBox>

Table Control控件:布局控件,可以对页面上的其他控件进行分组

       //     占用两行                  Canvas控件中位置                       大小                                        Grid控件的 位置

  1.  <TabControl Grid.RowSpan="2" Canvas.Left="10" Canvas.Top="2" Width="408" Height="208" Grid.Row="1">
  2.        //两个分组的名字
  3.          <TabItem Header="Game"/>         
  4.         <TabItem Header="Computer Player"/>
  5. </TabControl>

ListBox控件:多项选择框

        //  名字                                         水平布局                             大小             边距                       Grid第二行   

  1. <ListBox x:Name="playerNamesListBox" HorizontalAlignment="Left" Height="155" Margin="10,31,0,0" Grid.Row="2"
  2. //垂直布局                            大小               绑定的数据(显示的数据)
  3. VerticalAlignment="Top" Width="227" ItemsSource="{Binding Path=PlayerNames}"
  4. //选择改变的事件方法
  5. SelectionChanged="playerNamesListBox_SelectionChanged"/>

Menu菜单控件:MunuItem控件,

//         背景 色                                         字体加粗                  前景色

  1.  <Menu Background="Black" FontWeight="Bold" Foreground="White" >
  2. //       File菜单
  3.         <MenuItem Header="_File">
  4. //     File菜单的子选项 NewGame        前景色                 大小
  5.           <MenuItem Header="_New Game..." Foreground="Black" Width="200"
  6. // 命令参数   绑定的本地数据
  7. Command="local:GameViewModel.StartGameCommand" />
  8. //     File菜单的子选项Open    大小      前景色
  9.           <MenuItem Header="_Open" Width="200" Foreground="Black"/>
  10. //     File菜单的子选项Save   大小      前景色        命令参数
  11.           <MenuItem Header="_Save" Width="200" Foreground="Black" Command="Save">
  12. //  菜单的图标
  13.             <MenuItem.Icon>
  14.               <Image Source="Images\base_floppydisk_32.png" Width="20" />
  15.             </MenuItem.Icon>
  16.           </MenuItem>
  17. //分割线
  18.           <Separator Width="145" Foreground="Black"/>
  19.       </Menu>

猜你喜欢

转载自blog.csdn.net/QQhelphelp/article/details/86392218