29 Ocak 2011 Cumartesi
Show a Form in Another Form - mdi Forms
In this article, we will find out how to put a form into another form. As you know, when developing a desktop application, we mostly use more than one form. That means we should show them in one frame, because otherwise it does not seem good quite often.
After explanation, let's see the codes.
There are two forms in our project, named as ParentForm and ChildForm. There are two ways to generate ParentForm, one of them is generating a normal windows form and set its mdiParent property in its constructor, other one is that generating a mdi parent form.
In this example, we choose the first way. Here is our parent form,
Parent Form
Now, let's see the codes which are written into ParentForm.cs;
public partial class ParentForm : Form
{
public ParentForm()
{
this.IsMdiContainer = true; //This makes ParentForm a MdiContainer.
InitializeComponent();
ChildForm child = new ChildForm(); //New ChildFOrm object
child.MdiParent = this; //Sets ParentForm as parent of ChildForm
child.Dock = DockStyle.Fill; //Sets Dock property
child.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //Removes the frame of //ChildForm
child.Show; //Shows ChildForm
}
}
Here is the result;
See you in another article !
Basic File Operations in C#
Hello code lovers,
In this article, we will find out how to do basic file operations. As you know, these operations become very important for us especially where there is no connection to a database. So let's see the codes !
1. Writing to a text file: This operation writes the given content to a text file. If the file exists, it overwrites it, else generates a new text file.Let's see the code,
StreamWriter sw = new StreamWriter("C:/mytext.txt");
sw.WriteLine("I hate hello world :)");
sw.Close(); // This line is important, because if we don't close connection, it //doesn't allow to do a second operation on this file.
2. Reading content from a file: This operation reads content from a file.
StreamReader sr = new StreamReader("C:/mytext.txt");
string[] content=new string[20];
int i=0;
while(content!=null){
content[i]=sr.ReadLine();
i++;
}
StreamWriter sr = File.AppendText("C:/mytext.txt");
sr.WriteLine("My text is here !");
sr.Close();
C# ta Birkaç Path Tekniği
Merhaba arkadaşlar,
Bu yazıda birkaç path tekniğinden bahsedeceğim. Bildiğiniz gibi, yazdığımız programların, özellikle masaüstü
programları, birçoğu bilgisayarımızda bulunan klasörlerle etkileşim halinde. Bu sebeple, bazı path yöntemlerini
bilmemiz bize büyük fayda sağlayacaktır.
1. Sistem kullanıcı ismini öğrenme: Bu bilgiyle çeşitli pathlere ulaşmak mümkün olacak bizim için, mesela Belgelerim dosyasına ulaşırken
C:\Documents and Settings\"Kullanıcı Adı"\My Documents
pathinin kullanırız. Bunun için de, görüldüğü üzere kullanıcı adını bilmemiz gerekiyor. Bu ise .Net teknolojisi sayesinde çok basit,
System.Windows.Forms.SystemInformation.UserName
2. Bir klasördeki dosya isimlerine erişme : Bu yararlı işlem de aşağıdaki kodla gerçekleştirilebilir,
string[] filePaths = Directory.GetFiles(@"C:/Documents and Settings/Gözen/Desktop/degerler/");
burada, degerler klasörünün içindeki dosyaların isimleri filePaths isimli string dizisine atılır.
Directory.Exists(@"C:/Documents and Settings/Gözen/Desktop/degerler");
4. Path den dosya ismini uzantısı olmadan çekmek: Elimizde bulunan bir pathden dosyanın ismini çekmeye yarar.
string fileName = Path.GetFileNameWithoutExtension(@"C:/Documents and Settings/Gözen/Desktop/degerler/deneme.txt");
Burada döndürülen sonuç "deneme" dir.
Tahmin edeceğiniz üzere bunlardan çok daha fazla dosya işlemi .Net teknolojisi tarafından bize sağlanmaktadır, fakat kendimce en işe yarayanları
sizinle paylaşmak istedim. Bir dahaki yazıda görüşmek üzere. Esen kalın.
DataGrid den Excele Veri Aktarma
Merhaba arkadaşlar,
Bu yazıda DataGrid sınıfından türemiş bir nesneden Excele nasıl basitçe veri aktarabileceğini göstereceğim.
İnternette bununla alakalı çeşitli örnekler bulunmasına rağmen, bu yöntem daha kullanışlı olduğu için işimizi fazlasıyla görüyor.
Bunu da şu şekilde yapıyoruz,
Properties kısmında bulunan proje dosyaları arasından References isimli klasöre sağ tıklıyoruz ve Add Reference ye tıklıyoruz.
Burada, .Net tabında System.Web seçeneğini seçip OK butonuna tıklıyoruz.
string path="C:\\Documents and Settings\\Gözen\\Desktop";Böylelikle, DataGrid sınıfından türemiş bir nesneyle kendi excel dosyamızı oluşturmuş olduk. Bunu birçok yerde, özellikle raporlama, kullanabiliriz.
path+="\\myexcell.xlsx";
StreamWriter sw = new StreamWriter("path"); //Excelin oluşturulacağı path
HtmlTextWriter hw = new HtmlTextWriter(sw);
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
grid.DataSource=dt;
grid.DataBind();
grid.RenderControl(hw);
Şimdilik bu kadar, tekrar görüşmek üzere.
28 Ocak 2011 Cuma
OleDb ile Excelden Veri Çekme - Exporting content from Excel File via OleDb
Arkadaşlar merhaba,
23 Ocak 2011 Pazar
Creating a New JSF Project in Netbeans
Today, we are starting to learn the first step of JSF, how to create a new JSF project in netbeans !
Step 1: After opening netbeans in our computer, click the File->New Project selection.








Merhabalar Blogseverler !
Ben Emre Gözen. İTÜ Bilgisayar Mühendisliği 3. sınıf öğrencisiyim. Burada sizlerle, Java teknolojileri hakkında edindiğim tecrübeleri paylaşacağım. JSF projesi oluşturmaktan başlayıp, daha karmaşık yapılara doğru ilerleyeceğiz. Şimdiden herkese merhabalar, işe koyulma zamanı geldi !