60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.ComponentModel; | |||
|  | using System.Data; | |||
|  | using System.Drawing; | |||
|  | using System.Text; | |||
|  | using System.Windows.Forms; | |||
|  | using System.Drawing.Imaging; | |||
|  | 
 | |||
|  | namespace PDADemo | |||
|  | { | |||
|  |     public partial class PictureControl : Control | |||
|  |     { | |||
|  |         private int imageIndex = 0; | |||
|  | 
 | |||
|  |         public int ImageIndex | |||
|  |         { | |||
|  |             get { return imageIndex; } | |||
|  |             set | |||
|  |             { | |||
|  |                 imageIndex = value; | |||
|  |                 this.Invalidate(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private Image backgroundImage; | |||
|  | 
 | |||
|  |         public Image BackgroundImage | |||
|  |         { | |||
|  |             get { return backgroundImage; } | |||
|  |             set { backgroundImage = value; } | |||
|  |         } | |||
|  | 
 | |||
|  |         public PictureControl() | |||
|  |         { | |||
|  |         } | |||
|  | 
 | |||
|  |         protected override void OnPaint(PaintEventArgs pe) | |||
|  |         { | |||
|  |             // TODO: 在此处添加自定义绘制代码 | |||
|  | 
 | |||
|  |             SolidBrush brush = new SolidBrush(SystemColors.ActiveCaption); | |||
|  |             pe.Graphics.FillRectangle(brush, this.ClientRectangle); | |||
|  |             brush.Dispose(); | |||
|  | 
 | |||
|  |             if (this.BackgroundImage != null) | |||
|  |             { | |||
|  | 
 | |||
|  |                 ImageAttributes attr = new ImageAttributes(); | |||
|  |                 attr.SetColorKey(Color.Magenta, Color.Magenta); | |||
|  | 
 | |||
|  |                 pe.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, imageIndex * 16, 0, 16, 16, GraphicsUnit.Pixel, attr); | |||
|  | 
 | |||
|  |             } | |||
|  |             // 调用基类 OnPaint | |||
|  |             base.OnPaint(pe); | |||
|  |         } | |||
|  |     } | |||
|  | } |