:: Home

  login:         
  passwords:  

Winforms Interview Questions

Windows Forms Deployment
Windows Forms Controls
Windows Forms Data Binding
Windows Forms Datagrid
Windows Forms Docking
Windows Forms Keyboard Handling
Windows Forms Layout
Windows Forms Licensing
Windows Forms Menus
Windows Forms Mouse Handling
Windows Forms from MFC
Windows Forms from VB6
Windows Forms Patterns
Windows Forms Printing
Windows Forms Resources
Windows Form Scrolling
Windows Forms Tips
Windows Forms Common Dialogs
Windows Forms Listbox
Windows Forms ComboBox
Windows Forms Rich TextBox
Windows Forms ListView
Windows Forms TreeView
Windows Forms Button
Windows Forms TabControl
Windows Forms TextBox
Windows Forms MDI
Windows Forms Cursors
Windows Forms WebBrowser
Windows Forms PictureBox
Windows Forms Form
Windows Forms MDI
Windows Forms In IE
GDI+Bitmaps&Images
GDI+Font
GDI+Color
GDI+Brushes
GDI Drawing Tips
GDI+ from GDI
GDI Paths Regions
GDI+Pens
Interioerability WIn32
Tools Metadata Viewers
Design Time Serialization
Design Time Custom Designers
Design Time Tips
Design Time Type Editors
Vs.Net Tips
Vs.Net Debugging
Vs.Net Macros
Framework Tips General
Framework Tips Events
Framework Tips General IO
Framework Tips Strings
Framework Tips Threading
Tool Resource Editor
Design Time UI
Framework Tips CGI
Framework Tips XML

WPF Interview Qs

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Windows Forms PictureBox

The General Winforms Interview Questions consists the most frequently asked questions in Winforms. This list of 100+ questions guage your familiarity with the Winforms platform. The q&a have been collected over a period of time from various blogs, forums and other similar Winforms sites

29.Windows Forms PictureBox

    29.1 How can I place a border around a PictureBox?
    29.2 How can I copy a bitmap from the clipboard to a PictureBox?
    29.3 How can I copy and paste images/graphs etc from MS Office to a PictureBox?

29.1 How can I place a border around a PictureBox?

One solution is to use a panel that has a picturebox placed on it with DockStyle.Fill. This will make the picturebox assume the size of the panel. In addition, set the DockPadding.All property to the width of the desired border. Then in the Panel's OnPaint method, call the baseclass and then paint the desired borders.


The derived PicturePanel class has properties that allow you to set the bordersize and color as well as the image that is to be displayed. This sample retrieves the image from an embedded resource. It also uses double buffering to minimize flashing as you resize the control.


29.2 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)

29.3 How can I copy and paste images/graphs etc from MS Office to a PictureBox?

How can I copy and paste images/graphs etc from MS Office to a PictureBox?

[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();
}

Copyright 2007, Megasolutions Ltd
     
Copyright 2007, Megasolutions Ltd