|
using System.Drawing;
using System.Windows.Forms;
using BusinessObjects;
namespace WinFormsApp
{
/// <summary>
/// A WinForms control that displays an Employee object.
/// </summary>
public partial class EmployeeControl : UserControl
{
public EmployeeControl()
{
InitializeComponent();
// Convert the picture file path to a Bitmap.
Binding binding = this.employeePicture.DataBindings[0];
binding.Format += this.ConvertFilePathToBitmap;
}
void ConvertFilePathToBitmap(object sender, ConvertEventArgs e)
{
e.Value = Bitmap.FromFile(e.Value as string);
}
public Employee Employee
{
get { return this.employeeBindingSource.DataSource as Employee; }
set
{
this.employeeBindingSource.DataSource = value;
// The employee's picture shows a tooltip of their ID.
if (value != null)
{
string msg = "Employee ID: " + value.ID;
this.toolTip.SetToolTip(this.employeePicture, msg);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.