Beruflich Dokumente
Kultur Dokumente
Introduo
Prof. Srgio Fred
Aplicao Visual
Estrutura de GUI
GUI
Internal structure
Form
Button
Form
containers
Panel
Button
Panel
Label
Label
outros
Definir Projeto
Novo Projeto
Referenciar APIs
Estrutura de um programa
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace ProjetoConsole5
{
class Program : Form
{
static void Main(string[] args)
{
Application.Run(new Program());
}
}
}
9
Execuo do programa
10
Windows Application
anular o console
11
12
Construtor
...
class Program : Form
{
private Button button1;
private TextBox textbox1;
private ListBox listbox1;
private Program() {
inicializeComponentes();
}
private void inicializeComponentes()
{
listbox1= new ListBox();
textbox1 = new TextBox();
button1 = new Button();
Controls.AddRange(new Control[] {listbox,1 button1, textbox1});
}
static void Main(string[] args)
{
Application.Run(new Program());
}
} }
13
Construtor
private Program() {
inicializeComponentes();
}
Atributos do Form
//Atributos do form1
ClientSize = new Size(500, 500);
StartPosition = FormStartPosition.CenterScreen;
Controls.Add(button1);
Controls.Add(listbox1);
Controls.Add(textbox1);
//Controls.AddRange(new Control[] {button1,textbox1,listbox1});
this.Name = "Form1";
this.Text = "Sistema de Teste";
15
System.Drawing.Point
Representao para 2-D point
Constructor
Point(int x, int y)
Propriedades
X get/set of X coordinate
Y get/set of Y coordinate
16
System.Drawing.Size
Estrutura de largura e altura do objeto
Construtor
Size(int width, int height)
Propriedades
Width get/set width
Height get/set height
17
Windows Applications
public class GreetingForm : Form {
Label
greetingLabel;
Button cancelButton;
19
{
20
Popular um ListBox
Adicionar valores no ListBox
Converter para String com ToString()
for(int i = 0; i < 50; i++) {
listBox1.Items.Add("Item " + i.ToString());
}
21
Sada de mensagem
22
DataGridView
23
Colunas no DataGridView
24
int L, C;
int[,] A = new int[3,5];
int[,] S = new int[3,5]
Preencher dataViewGrid
public Form1()
{
InitializeComponent();
dataGridView2.Enabled = true;
}
Listar Elementos
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int Lin = Convert.ToInt32(textBox2.Text);
int Col = Convert.ToInt32(textBox3.Text);
textBox1.Clear();
for (L = 0; L < Lin; ++L)
{
for (C = 0; C < Col; ++C)
{
DataGridViewCell celula = dataGridView1[C, L];
vet[L, C] = Convert.ToInt32(celula.Value);
textBox1.AppendText("Posio ["+L+","+C+"]..."+Convert.ToString(vet[L, C]) + "\n");
}
}
}
}
}
}
}
}
Form2
...
using System.Drawing;
using System.Windows.Forms;
namespace datagrid1
{
class Class1 : Form
{
public Class1()
{
inicializar();
}
30
Serializao/Desserializao
31
32
Leitura no arquivo
private void botao2_click(object sender, EventArgs e) {
string Caminho = "C:\\CodeGear_\\arq01.txt";
StreamReader arquivo = File.OpenText(Caminho);
string linhas = arquivo.ReadLine();
tx1.AppendText(linhas);
// while (linha != null)
// {
//
tx1.AppendText(linhas);
//
linha = leitor.ReadLine();
// }
arquivo.Close();
}
33
Pesquisa no Arquivo
StreamReader
public override string Consultar(string nome)
{
StreamReader sr = new StreamReader(@"D:\lientes.txt");
while (!sr.EndOfStream)
{
if (sr.ReadLine().Contains(nome))
{
registro = sr.ReadLine();
}
}
return registro;
}
34
Pesquisa no Arquivo
StreamReader
while (!sr.EndOfStream)
{
var texto = sr.ReadLine();
if (texto.Contains(nome))
{
registro = texto;
}
}
35
Pesquisa no Arquivo
36
TreeView
37
TreeView
38
TreeView
treeView1.Sele
treeView1.SelectedNode.
tedNode.FullPath.
FullPath.ToString ();
treeView1.CheckBoxes
treeView1.CheckBoxes = true;
true;
39
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TreeNode tNode ;
tNode = treeView1.Nodes.Add("Websites");
treeView1.Nodes[0].Nodes.Add("Net-informations.com");
treeView1.Nodes[0].Nodes[0].Nodes.Add("CLR");
treeView1.Nodes[0].Nodes.Add("Vb.net-informations.com");
treeView1.Nodes[0].Nodes[1].Nodes.Add("String Tutorial");
treeView1.Nodes[0].Nodes[1].Nodes.Add("Excel Tutorial");
treeView1.Nodes[0].Nodes.Add("Csharp.net-informations.com");
treeView1.Nodes[0].Nodes[2].Nodes.Add("ADO.NET");
treeView1.Nodes[0].Nodes[2].Nodes[0].Nodes.Add("Dataset");
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(treeView1.SelectedNode.FullPath.ToString ());
}
}
}
40
TreeView
41
TreeView.Nodes
42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[] vetorX = {2,3,4};
int[] vetorY = { 1, 2, 5 };
chart1.Series["Series1"].Points.DataBindXY(vetorX, vetorY);
//series1.ChartType = SeriesChartType.Line;
}
}
}