using System; using System.Windows.Forms; using System.Drawing; class Lohistamine:Form{ Label silt1=new Label(); Label silt2=new Label(); TextBox tekst1=new TextBox(); public Lohistamine(){ silt1.Location=new Point(20, 30); silt2.Location=new Point(150, 30); tekst1.Location=new Point(80, 60); silt1.Text="Vasak"; silt2.Text="Parem"; this.Text="Lohista sildi tekst kasti"; //Vormi pealkiri Controls.Add(silt1); Controls.Add(silt2); Controls.Add(tekst1); silt1.MouseDown+=nupuvajutus; silt2.MouseDown+=nupuvajutus; tekst1.DragEnter+=tekst1_DragEnter; tekst1.DragDrop+=tekst1_DragDrop; tekst1.AllowDrop=true; } void nupuvajutus(object saatja, EventArgs e){ if(saatja==silt1){ silt1.DoDragDrop(silt1.Text, DragDropEffects.Copy); } if(saatja==silt2){ silt2.DoDragDrop(silt2.Text, DragDropEffects.Copy); } } void tekst1_DragEnter(object saatja, DragEventArgs e){ if (e.Data.GetDataPresent(DataFormats.Text)) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } void tekst1_DragDrop(object sender, DragEventArgs e) { tekst1.Text = e.Data.GetData(DataFormats.Text).ToString(); } [STAThread] public static void Main(string[] arg){ Application.Run(new Lohistamine()); } }