04 Ocak 2010 Pazartesi

RichTextBox Zoomlama

RichTextBox nesnesinde zoom in, zoom out nasıl oluyor? ile ilgili bir örneğe bakacağız. Formunuza 3 adet Button ekleyin. Yine Formunuzun Classına using System.Diagnostics; i ekleyin.


Şekil 1

Form1.cs

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

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked);

}

private void button1_Click(object sender, EventArgs e)

{

//richTextBox taki yazıları küçültüyoruz.

float zoom = richTextBox1.ZoomFactor;

if (zoom / 2 > 0.015625)

richTextBox1.ZoomFactor = zoom / 2;

}

private void button2_Click(object sender, EventArgs e)

{

//richTextBox taki yazıları büyütüyoruz.

float zoom = richTextBox1.ZoomFactor;

if (zoom * 2 <>

richTextBox1.ZoomFactor = zoom * 2;

}

private void button3_Click(object sender, EventArgs e)

{

//richTextBox gerçek boyut

richTextBox1.ZoomFactor = 1f;

}

private void richTextBox1_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)

{

//richTextBox taki linkleri iexplorer da açıyoruz.

Process p = new Process();

p.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";

p.StartInfo.Arguments = e.LinkText;

p.Start();

}

}

}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN



29 Aralık 2009 Salı

Ziyaretçi İstatistiklerini Almak

Web sayfamızı ziyaret eden ziyaretçilerin hangi sayfalara girdikleri, ip numaralarını, giriş tarihlerini, hangi tarayıcı kullandıklarını kaydedeceğiz. Bunun için Global.asax ta Application_BeginRequest(object sender, EventArgs e) e aşağıdaki kodları yazacağız.



Şekil 1


Global.asax

< %@ Import Namespace="System.Data.OleDb" % >
< %@ Application Language="C#" % >
< runat="server">

protected void Application_BeginRequest(object sender, EventArgs e)
{
string str = "Insert into ziyaretci (url,sayfa,ip,kaynak,tarih) values(@url,@sayfa,@ip,@kaynak,@tarih)";

OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");

OleDbCommand komut = new OleDbCommand(str, baglan);

komut.Parameters.AddWithValue("@url", Request.ServerVariables["URL"].ToString());

komut.Parameters.AddWithValue("@sayfa", Request.ServerVariables["Query_String"].ToString());

komut.Parameters.AddWithValue("@ip", Request.ServerVariables["Remote_Addr"].ToString());

komut.Parameters.AddWithValue("@kaynak", Request.ServerVariables["Http_User_Agent"].ToString());

komut.Parameters.AddWithValue("@tarih", DateTime.Now.ToString());

baglan.Open();

komut.ExecuteNonQuery();

baglan.Close();
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started

}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

}

< / script >


Default.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "Select * From ziyaretci";

OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");
OleDbDataAdapter adp = new OleDbDataAdapter(str, baglan);
OleDbCommand komut = new OleDbCommand(str, baglan);

baglan.Open();
DataSet ds= new DataSet();
adp.Fill(ds);

GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

baglan.Close();
}
}



Default.aspx.cs




Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

17 Aralık 2009 Perşembe

Process Uygulaması

Merhaba arkadaşlar, Process nesnesi ile uygulama açmayı göreceğiz. Bu örnekte NotePad i açıp, 5 saniye sonra otomatik olarak uygulamanın kapanmasını göreceğiz.

Formunuza;


using System.Diagnostics;

using System.Threading;


ekleyin.

Form1.cs


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

using System.Threading;

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Process process = new Process();

process.StartInfo.FileName = "Notepad";

//NotePad i açıyoruz.

process.Start();

process.WaitForInputIdle();

Thread.Sleep(5000);

if (!process.CloseMainWindow())

{

//5 saniye sonra açtığımız uygulama

//kapatılıyor.

process.Kill();

}

}

}

}


Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

15 Aralık 2009 Salı

Split Metodu()

Merhaba arkadaşlar, bu makalemizde Split metoduna değineceğiz. Split metodunu kullanarak belirtilen karaktere göre kelimeleri birbirinden ayırabilirsiniz. Ör: boşluk, ?, ‘, _ gibi karakterleri bu metodla tanımlayarak Stringinizi istediğiniz yerden birden fazla şekilde ayırabilirsiniz.

Form1.cs

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 WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string str = "Bahadır ŞAHİN";

string[] i;

/*Burada boşluk karakterine göre ayırımı yaptık.

Eğer boşluğa göre değilde farklı karaktere göre

ayırım yaparsakÖr: ? işaretine göre

string str = "Bahadır?ŞAHİN";

i = str.Split('?'); şeklinde yazacağız

*/

i = str.Split();

textBox1.Text = i[0];

textBox2.Text = i[1];

}

}

}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

10 Aralık 2009 Perşembe

Form daki CheckBox ların Seçimini Topluca Kaldırma

Merhaba arkadaşlar, formumuzda bulunan 100 lerce seçili CheckBox ın seçili durumunu tek tek kaldırmanın ne kadar zor olduğunu hepimiz biliyoruz.100 lerce veya 1000 lerce içi dolu TextBoxlar ın içeriğini değiştirmek veya temizlemek çok zor bir iştir. Bu zorluklardan küçük bir kod parçasıyla kurtulacağız.

Form1.cs


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 WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

foreach (var kontrol in this.Controls)

{

//Seçili olan bütün checkboxların

//seçili olma durumunu kaldırıyoruz.

CheckBox cbox = new CheckBox();

if (kontrol is CheckBox)

{

cbox = (CheckBox)kontrol;

cbox.Checked = false;

}

}

}

private void button1_Click(object sender, EventArgs e)

{

//Şimdi de birden fazla textbox ın içeriğini

//topluca temizliyelim.

foreach (var kontrol in this.Controls)

{

TextBox tbox = new TextBox();

if (kontrol is TextBox)

{

tbox = (TextBox)kontrol;

tbox.Text = string.Empty;

}

}

}

}

}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

05 Aralık 2009 Cumartesi

ListView İle Veritabanı Bağlantısı-2

Merhaba arkadaşlar, bu makalemizde Access veritabanındaki bilgileri ListView nesnemizde göstereceğiz. (Şekil 1)



Şekil 1

Form1.cs

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.Data.OleDb;

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

string str = "provider=Microsoft.Jet.Oledb.4.0;Data Source=bilgi.mdb";

listView1.View = View.Details;

listView1.GridLines = true;

listView1.Columns.Add("id", 30);

listView1.Columns.Add("Ad", 60);

listView1.Columns.Add("Soyad", 60);

listView1.Columns.Add("Ogrenim", 60);

string sql = "Select * From personel";

OleDbConnection baglan = new OleDbConnection();

baglan.ConnectionString = str;

baglan.Open();

OleDbCommand komut =new OleDbCommand(sql, baglan);

OleDbDataReader dr = komut.ExecuteReader();

ListViewItem item = new ListViewItem();

while (dr.Read())

for ( int i=1 ; i <= 1; i++)

{

item = listView1.Items.Add(dr.GetInt32(0).ToString());

item.SubItems.Add(dr.GetString(1));

item.SubItems.Add(dr.GetString(2));

item.SubItems.Add(dr.GetString(3));

}

baglan.Close();

}

}

}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

22 Kasım 2009 Pazar

TextBoxları Birleştirme

Merhaba arkadaşlar, Concat metodunu kullanarak TextBox taki stringleri birleştireceğiz. Formunuza 3 adet TextBox, 1 adet Label ve Button ekleyin. (Şekil 1)


Şekil 1

Form1.cs

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim str(2) As String

str(0) = TextBox1.Text

str(1) = TextBox2.Text

str(2) = TextBox3.Text

Label1.Text = String.Concat(str(0), str(1), str(2))

End Sub

End Class

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN

20 Kasım 2009 Cuma

Excel Dosyası Oluşturma

Bu örneğimizde Excel dosyası oluşturacağız. Formunuza 1 adet Button ekleyin ve aşağıdaki kodları yazın.


Şekil 1


Şekil 2

Form1.vb

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

Dim excelobject = CreateObject("excel.application")

excelobject.Workbooks.Add()

excelobject.ActiveWorkbook.SaveAs(Filename:="C:\test")

excelobject.Activesheet.Range("A1").value = "test amaçlı oluşturuldu."

excelobject.Activeworkbook.Save()

excelobject.Quit()

MsgBox("test.xls excel dosyası oluşturuldu.")

Catch ex As Exception

MsgBox("Hata oluştu...")

End Try

End Sub

End Class

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşünceye kadar hoş cakalın. Bahadır ŞAHİN.

19 Kasım 2009 Perşembe

Forum Sitemiz Açıldı

Forum sitemiz açıldı. Yeni forum sitemizde Programlama, Network, Microsoft ve Cisco Sertifikaları gibi konular olacak.
Makalelerinizle, dökümanlarınızla, açıklayıcı bilgilerinizle Siz değerli arkadaşların Forum sitemize katkılarınızı bekliyoruz.

Bilgi paylaşıldıkça güzeldir.

Forum sitemize BURADAN girebilirsiniz.

17 Kasım 2009 Salı

Dosya Uzantısı Arama

Merhaba arkadaşlar, bu örnekte TextBox a girilen dosya uzantılarını arayıp, ListBox ta gösterimini sağlayacağız. Şekil 1 de görüldüğü gibi C dizininde arama yaptık.


Şekil 1

Form1.cs

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 btnAra_Click(object sender, EventArgs e)

{

listBox1.Items.Clear();

//C deki aranacak olan uzantıyı alt klasörlerde de arar.

//listBox1.Items.AddRange(Directory.GetFiles("C:\\", txtAra.Text, SearchOption.AllDirectories));

//sadece C dizininde aramak için;

listBox1.Items.AddRange(Directory.GetFiles("C:\\", txtAra.Text, SearchOption.TopDirectoryOnly));

}

}

}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşünceye kadar hoşcakalın. Bahadır ŞAHİN