当前位置: 首页 > 图文教程 > 开发语言 > VB > 图象显示和翻转控件(用户自定义控件)

VB
Visual Basic.NET中访问数据的方法
巧解VB安装程序制作
优化之路:精简VB程序的代码
VB.NET窗体操作技巧两则
Visual Basic数据库开发疑难问题解
利用VB驱动pcAnyWhere进行自动文件传输
用VB实现窗口图标最小化到通知栏
VB6实现局域网多站点互连完全手册

VB 中的 图象显示和翻转控件(用户自定义控件)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-29   浏览: 129 ::
收藏到网摘: n/a

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace ImageZoomer
{
///


///
///


//枚举类型定义,定义图象的四种翻转方式
public enum FlipModeStyle
{
NoFlip=0,//不翻转
FlipX=1,//水平翻转
FlipY=2,//垂直翻转
FlipXY=3//水平垂直翻转
}

//事件数据类定义,报告图象的显示尺寸
public class DisplaySizeChangedEventArgs:System.EventArgs
{
public int Width;
public int Height;
public DisplaySizeChangedEventArgs()
{
}
}

//事件代表的声明
public delegate void DisplaySizeChangedEventHandler(object sender,DisplaySizeChangedEventArgs e);

//用户自定义控件类
public class ImageZoomerControl : System.Windows.Forms.Control
{
private int width;//控件宽度
private int height;//控件高度
private System.Drawing.Bitmap bitmap;//控件上的图象
private FlipModeStyle flip;//图象的翻转方式
private event DisplaySizeChangedEventHandler eventHandler;//事件

//构造方法,初始化数据成员
public ImageZoomerControl()
{
width=this.width;
height=this.height;
bitmap=null;
eventHandler=null;
}

//宽度属性
[
Category("ImageZoomer"),
Description("The displayed image width.")
]
public int DisplayWidth
{
get
{
return width;
}
set
{
if(value>=0)
{
width=value;
Invalidate(this.ClientRectangle);
}
}
}

//高度属性
[
Category("ImageZoomer"),
Description("The displayed image height.")
]
public int DisplayHeight
{
get
{
return height;
}
set
{
if(value>=0)
{
height=value;
this.Invalidate(this.ClientRectangle);
}
}
}

//图象属性
[
Category("ImageZoomer"),
Description("The image displayed by this control."),
DefaultValue(null)
]
public Bitmap DisplayImage
{
get
{
return bitmap;
}
set
{
bitmap=value;
if(bitmap!=null)
{
width=bitmap.Width;
height=bitmap.Height;
}
else
{
width=this.width;
height=this.height;
}
this.Invalidate(this.ClientRectangle);
}
}

//翻转方式属性
[
Category("ImageZoomer"),
Description("Specify how the image will be flipped.")
]
public FlipModeStyle FlipMode
{
get
{
return flip;
}
set
{
flip=value;
this.Invalidate(this.ClientRectangle);
}
}

//事件属性
[
Category("ImageZoomer"),
Description("Occurs when the image size is changed.")