Advertisement
Nannoka

ControleWPF

Apr 1st, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. >>>>Tela WPF<<<<
  2.  
  3. <Window
  4.     x:Class="MainWindow"
  5.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7.     Title="MainWindow"
  8.     Height="350"
  9.     Width="525">
  10.     <Grid>
  11.        
  12.         <Grid.RowDefinitions>
  13.             <RowDefinition />
  14.             <RowDefinition />
  15.             <RowDefinition />
  16.             <RowDefinition />
  17.             <RowDefinition />
  18.             <RowDefinition />
  19.         </Grid.RowDefinitions>
  20.  
  21.         <Grid.ColumnDefinitions>
  22.             <ColumnDefinition
  23.                 Width="*" />
  24.             <ColumnDefinition
  25.                 Width="3*" />
  26.         </Grid.ColumnDefinitions>
  27.         <Button Content="Gravar"
  28.                 Grid.Column="1"
  29.                 HorizontalAlignment="Left"
  30.                 VerticalAlignment="Top"
  31.                 Width="75"
  32.             Grid.Row="5"
  33.                 Name="btnGravar"
  34.                 Click="btnGravar_Click"/>
  35.  
  36.         <Label
  37.             Content="Nome"
  38.             HorizontalAlignment="Right"
  39.             VerticalAlignment="Center"
  40.             />
  41.  
  42.         <Label
  43.             Content="Sexo"
  44.             HorizontalAlignment="Right"
  45.             VerticalAlignment="Center"
  46.             Grid.Row="1" />
  47.  
  48.         <Label
  49.             Content="Estado civil"
  50.             HorizontalAlignment="Right"
  51.             VerticalAlignment="Center"
  52.             Grid.Row="2" />
  53.  
  54.         <Label
  55.             Content="Data de Nascimento"
  56.             HorizontalAlignment="Right"
  57.             VerticalAlignment="Center"
  58.             Grid.Row="3" />
  59.  
  60.         <Label
  61.             Content="Hobies"
  62.             HorizontalAlignment="Right"
  63.             VerticalAlignment="Center"
  64.             Grid.Row="4" />
  65.  
  66.         <TextBox
  67.             Grid.Column="1"
  68.             Margin="0 10 30 0"
  69.             Name="txtNome"/>
  70.  
  71.         <StackPanel Grid.Column="1"
  72.                       Grid.Row="1"
  73.                    Orientation="Horizontal"
  74.                     Margin="0 10 30 10"
  75.                     VerticalAlignment="Center">
  76.             <RadioButton Content="Masculino"
  77.                          Margin="0 0 10 0"/>
  78.             <RadioButton
  79.                 Content="Feminino"
  80.                 Margin="0 0 10 0" />
  81.         </StackPanel>
  82.  
  83.         <ComboBox Grid.Column="1"
  84.                   Grid.Row="2"
  85.                   Margin="0 10 30 10">
  86.            
  87.             <ComboBoxItem Content="Selecione"
  88.                           IsSelected="True" />
  89.             <ComboBoxItem Content="Casado" />
  90.             <ComboBoxItem Content="Solteiro" />
  91.         </ComboBox>
  92.  
  93.         <DatePicker
  94.             Grid.Column="1"
  95.             Grid.Row="3"
  96.             Margin="0 10 30 10"
  97.             Name="dtpNascimento"/>
  98.  
  99.         <StackPanel
  100.             Grid.Column="1"
  101.             Grid.Row="4"
  102.             Margin="0 10 30 10" />
  103.  
  104.         <StackPanel
  105.             Grid.Column="1"
  106.             Grid.Row="4"
  107.             Orientation="Horizontal"
  108.             VerticalAlignment="Center">
  109.  
  110.             <CheckBox Margin="0 0 15 0" Content="Caminhar"
  111.                       Name="chkCaminhar"/>
  112.             <CheckBox Margin="0 0 15 0" Content="Ler"
  113.                       Name="chkLer"/>
  114.             <CheckBox Margin="0 0 15 0" Content="Pasear"
  115.                       Name="chkPassear"/>
  116.          </StackPanel>
  117.          
  118.     </Grid>
  119. </Window>
  120.  
  121.  
  122.  
  123. >>>Main<<<
  124.  
  125. using System;
  126. using System.Collections.Generic;
  127. using System.Linq;
  128. using System.Text;
  129. using System.Threading.Tasks;
  130. using System.Windows;
  131. using System.Windows.Controls;
  132. using System.Windows.Data;
  133. using System.Windows.Documents;
  134. using System.Windows.Input;
  135. using System.Windows.Media;
  136. using System.Windows.Media.Imaging;
  137. using System.Windows.Navigation;
  138. using System.Windows.Shapes;
  139.  
  140. namespace ControleWPF
  141. {
  142.     /// <summary>
  143.     /// Interaction logic for MainWindow.xaml
  144.     /// </summary>
  145.     public partial class MainWindow : Window
  146.     {
  147.         public MainWindow()
  148.         {
  149.             InitializeComponent();
  150.         }
  151.  
  152.         private void btnGravar_Click(object sender, RoutedEventArgs e)
  153.         {
  154.               StringBuilder sb = new StringBuilder();
  155.         sb.Append("Nome" + txtNome.Text + "\n\n");
  156.  
  157.         string sexo = (bool)radMasculino.IsChecked ? "Masculino" : "Feminino";
  158.         sb.Append("Sexo" + sexo);
  159.  
  160.         string estadoCivil = CboCasado.IsSelected ? "Casado" : "Solteiro";
  161.         sb.Append("Estado Civil" + estadoCivil);
  162.  
  163.         DateTime dataNascimento = (DateTime)dtpNascimento.SelectedDate;
  164.         sb.Append("Data de nascimento" + dataNascimento.ToShortDateString() + "\n\n");
  165.  
  166.         string hobbies = (bool)chkCaminhar.IsChecked ? "Caminhar" : "";
  167.         hobbies += (bool)chkLer.IsChecked ? ", Ler" : "";
  168.         hobbies += (bool)chkPassear.IsChecked ? ", Passear" : "";
  169.         sb.Append("Hobbies: " + hobbies);
  170.  
  171.        MessageBox.Show(sb.ToString());
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement