Export (0) Print
Expand All

Creating a Custom Control (Visual C#) 

Visual Studio 2005

Download sample

This Visual C# sample demonstrates making a two-line ListView custom control, including a WYSIWYG design-time experience.

The sample can be built for Pocket PC or Smartphone, using either version 1.0 or version 2.0 of the .NET Compact Framework.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To run this sample

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

    Make sure that the Show extracted files check box is selected, and then click Finish.

  4. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

What this Sample Demonstrates

This sample illustrates how to implement a TwoLineListBox custom control using custom drawing with full design-time support, including the following techniques:

  • Custom paint control appearance using classes from System.Drawing and System.Drawing.Imaging namespaces.

  • Event handling to redraw a custom control.

  • Using databinding to load data from a data source to populate the control.

  • Displaying an image in a custom control.

  • Adding design-time support for description, category, and other properties and events by using Class Diagram and DesignTimeAttributes.

  • Adding design-time support to bind a control to an existing data source.

  • Applying DataSourceListEditor and DataMemberFieldEditor to properties (DataSource, Data) through DesignTimeAttributes.

  • Applying Custom editor (Contact Editor) to property (Context) through DesignTimeAttributes.

  • Setting a default value for some properties, such as Line1DisplayMember, Line2DisplayMember.

  • Serializing the collection property to code from the custom editor, Contact Editor.

  • Deserializing the collection property to a custom editor, Contact Editor, from code.

  • Serializing an image from the custom editor, Contact Editor, into a .resx file.

  • Deserializing an image from a .resx file into the custom editor, Contact Editor.

Community Additions

ADD
Show:
© 2014 Microsoft