listbox’tan listbox’a Sürükle Bırak (Drag Drop) C#.Net

listbox’tan listbox’a Sürükle Bırak C#

Daha fazla bilgi için : www.gorselprogramlama.com

Soru: listbox1’deki kişiyi sürükle bırak yöntemi ile listbox2’ye aktaran programın kodlarını yazınız.

[code language=”csharp”]

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 listbox_dragdrop

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void listBox1_MouseDown(object sender, MouseEventArgs e)

{

Point n= new Point(e.X, e.Y);

int i= listBox1.IndexFromPoint(n);

if (e.Button==MouseButtons.Left)

{

listBox1.DoDragDrop(listBox1.Items[i], DragDropEffects.All);

}

}

private void listBox2_DragOver(object sender, DragEventArgs e)

{

if (e.KeyState==1)

{

e.Effect = DragDropEffects.Move;

}

}//Daha fazla bilgi için : www.gorselprogramlama.com

private void listBox2_DragDrop(object sender, DragEventArgs e)

{

listBox2.Items.Add(e.Data.GetData(DataFormats.Text).ToString());

}

}

}

[/code]

mouse ile sürükleyerek ali’yi listbox2’ye aktaralım.

Daha fazla bilgi için : www.gorselprogramlama.com

Yorumlar 3

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir