Where can I find a VB.Net to C# code converter ?
Please try the following link for this purpose : http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
How can I copy and paste images/graphs etc from MS Office to a PictureBox?
Since .NET uses it’s own format that is not compatible with the EnhancedMetafile format you will have to use reflection to achieve this. (From a posting in the microsoft.public.dotnet.framework.drawing newsgroup) [C#] using System.Runtime.InteropServices; using System.Reflection; public const uint CF_METAFILEPICT = 3; public const uint CF_ENHMETAFILE = 14; [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool OpenClipboard(IntPtr hWndNewOwner); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool CloseClipboard(); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern IntPtr GetClipboardData(uint format); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool IsClipboardFormatAvailable(uint format); //Pasting into PictureBox if (OpenClipboard(this.Handle)) { if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { IntPtr ptr = GetClipboardData(CF_ENHMETAFILE); if (!ptr.Equals(new IntPtr(0))) { Metafile metafile = new Metafile(ptr,true); //Set the Image Property of PictureBox this.pictureBox1.Image = metafile; } } CloseClipboard(); }
How can I copy a bitmap from the clipboard to a PictureBox?
This code snippet shows how you can set your PictureBox’s image to be the image from the clipboard: [C#] this.pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap); [VB.Net] Me.pictureBox1.Image = CType(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
How can I programmatically create a bitmap
Since .NET uses it’s own format that is not compatible with the EnhancedMetafile format you will have to use reflection to achieve this. (From a posting in the microsoft.public.dotnet.framework.drawing newsgroup) [C#] using System.Runtime.InteropServices; using System.Reflection; public const uint CF_METAFILEPICT = 3; public const uint CF_ENHMETAFILE = 14; [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool OpenClipboard(IntPtr hWndNewOwner); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool CloseClipboard(); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern IntPtr GetClipboardData(uint format); [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool IsClipboardFormatAvailable(uint format); //Pasting into PictureBox if (OpenClipboard(this.Handle)) { if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { IntPtr ptr = GetClipboardData(CF_ENHMETAFILE); if (!ptr.Equals(new IntPtr(0))) { Metafile metafile = new Metafile(ptr,true); //Set the Image Property of PictureBox this.pictureBox1.Image = metafile; } } CloseClipboard(); }
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