How can I drag and drop an image from one PictureBox to another?

The following code snippet demonstrates how you can drag and copy an image from one picturebox (Source) another (Target: [C#] //In the Form Load //Set AllowDrop of the Target PictureBox to true as this property cannot be set in the Designer this.pictureBox2.AllowDrop = true; //Source PictureBox private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) pictureBox1.DoDragDrop( pictureBox1.Image, DragDropEffects.All ); } //Target PictureBox //Drag Drop Effects private void pictureBox2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { if ( e.Data.GetDataPresent( DataFormats.Bitmap ) ) { e.Effect = DragDropEffects.Copy; } else e.Effect = DragDropEffects.None; } //Set the image to be the dragged image. private void pictureBox2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if ( (e.Data.GetDataPresent(DataFormats.Bitmap))) { this.pictureBox1.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap)); } } [VB.NET] ’In the Form Load ’Set AllowDrop of the Target PictureBox to true as this property cannot be set in the Designer Me.pictureBox2.AllowDrop = True ’Source PictureBox Private Sub pictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.All) End If End Sub ’Target PictureBox ’Drag Drop Effects Private Sub pictureBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) If e.Data.GetDataPresent(DataFormats.Bitmap) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub ’Set the image to be the dragged image. Private Sub pictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) If (e.Data.GetDataPresent(DataFormats.Bitmap)) Then Me.pictureBox1.Image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap) End If End Sub

In a debug build, how do I write debug information to the output window (similar to the TRACE macro from VC6)

You can use the Console.Write and Console.WriteLine methods from within a Windows Forms project to do this. The class DefaultTraceListener is used to implement this functionality. When your application is launched from the VS.NET IDE in Debug mode, you will see all trace and debug messages in the Output window by calling: System.Diagnostics.Trace.WriteLine() or System.Diagnostics.Debug.WriteLine()

How do you implement TopLevel Controls

TopLevel controls (like Form) cannot be added into Controls list using Controls.Add(). For example, if you are trying to add a form into a Panel’s control list, it will lead you to an exception ‘Top-level control cannot be added to a control’. To avoid this exception, you need to set the form’s TopLevel property to false. Form form2 = new Form(); form2.TopLevel = false; this.panel1.Controls.Add(form2);

In VB.NET how do I access the runtime type object of a specified type from it’s type name?

Visual Basic has a GetType operator that can be used to obtain the System.Type object for the specified type name. This is the equivalent of the typeof keyword in C#. ’ Returns the System.RuntimeType object representing the integer type. Dim inttype As Type = GetType(Integer) ’ Returns the System.RuntimeType object representing the Project1.Type1 class. Dim mytype As Type = GetType(Project1.Type1)