3 Ağustos 2009 Pazartesi

GUI lere hızlı bir başlangıç

Eğer c#'a c gözüyle bakıp o hızla ilerlemeye kalkarsam çok yanılırım.Bu yüzden hemen gui'lere bir başlangıç yapmam gerekiyordu.Gui bileşenlerini tanımaya ve özelliklerini anlamaya başlamak şart oldu.Hemen bir panel yapıp içini check boxlarla doldurdum.Bunun yanında bir buton ve sonucu yazdırmak için bir de label koydum.Program butona basıldığında kaç check box'ın işaretli olduğunu label'a yazdıracak.

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;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int i, sayac = 0;
foreach (Control item in panel1.Controls)
{
if (item.GetType() == typeof(CheckBox))
{
CheckBox chk = (CheckBox)item;
if (chk.Checked)
sayac++;
}
}

label1.Text = sayac.ToString();
}
}
}

Gayet güzel:)
Ama kesinlikle yeterli değil:) Windows Form Application oluşturup küçük bir nodepad uygulaması yaptım.

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.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
//txt uzantılı dosyaları filtreler
openFileDialog1.Filter = "Text files|*.txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)

{
string file = openFileDialog1.FileName;
Stream strem = openFileDialog1.OpenFile();
//windowsun türkçe karakter kodlaması 1254 olduğu için dosyanın içindeki türkçe karakterler sorunsuz gösterilir
StreamReader read = new StreamReader(strem, System.Text.Encoding.GetEncoding(1254));
richTextBox1.Text= read.ReadToEnd();

}
}

private void Form1_Load(object sender, EventArgs e)
{


}

private void button2_Click(object sender, EventArgs e)
//txt uzantılı dosyaları filtreler
{saveFileDialog1.Filter = "Text files|*.txt";
//diyalog penceresinde tamama basıldığında
if (saveFileDialog1.ShowDialog() == DialogResult.OK){
string file = saveFileDialog1.FileName;

richTextBox1.SaveFile(file);

}
}

}
}

Herbir kontrolün kendine ait birçok özelliği var ve kullanılarak tecrübe edilerek öğrenilecek şeyler.Çok çalışmam lazım:)

Hiç yorum yok: