asp.net Control Development Series VI

Source: Internet
Author: User

Uitypeedit

"I want the Red Peach."

If, you're doing a "poker" control, the poker has a property--suit, you want the user to choose the color of this attribute, the property window presents not only the text, there is a small color icon to indicate the color, "red peach" There is a small "red peach" icon in front of the show, "spades" there is a "spade" Icons appear in front, just as you choose the BackColor of other controls, there is a small square color before the color to indicate the selected color, more considerate design ah.

Now, we're going to do this thing:

public class Squeezer
{
.
public CardTypes CardType
{
}
}
[Editor(typeof(CardTypesEditor), typeof(System.Drawing.Design.UITypeEditor))]
public class CardTypes
{
..
}
public class CardTypesEditor : UITypeEditor
{
  public override bool GetPaintValueSupported(ITypeDescriptorContext context)
  {
  return true;//支持画小图
  }
  public override void PaintValue(PaintValueEventArgs pe) //定义根据值画小图的逻辑
  {
  string bmpName = null;
  CardTypes C = (CardTyes)pe.Value;
  switch(C.Value)
  {
   case CarderTypes.HongTao:
   bmpName = "红桃.bmp";//图片必须是嵌入的资源,大小为16*16,类型为BMP
   break;
  }
  Bitmap b = new Bitmap(typeof(GradeEditor), bmpName);
  pe.Graphics.DrawImage(b, pe.Bounds);
  b.Dispose(); 
  }
}

In the above code, we use the EditorAttribute to make the color class and a editor association, and then through the editor to achieve the function of drawing schematic diagram.

Well, now your creativity may be agitating you to think about a new problem, I don't want to let the user select the value of the attribute simply by rendering a simple drop-down list of values (implemented through Enumconverter), I want to implement the values like BackColor, The dock is such a friendly interaction with the user, well, let's go to the next step.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.