首 页 ┆ 源码下载 ┆ IT学院 ┆ 字体下载 ┆ 模板下载 ┆ 源码发布 ┆ 广告合作 ┆ 网站地图 ┆ 虚拟主机 ┆ 中文域名
► 设为首页
► 加入收藏
► 联系我们
源码下载 >> ASP源码 | PHP源码 | ASP.net源码 | JSP源码 | CGI源码 | VC/C++源码 | VB源码 | Delphi源码 | Flash源码
文章学院 >> 网络编程 | 网页设计 | 图形图象 | 数据库 | 服务器 | 网络媒体 | 网络安全 | 操作系统 | 办公软件 | 软件开发 | 黑客知识
字体下载 >> 精制字体 | 非英字体 | 艺术字体 | 著名字体 | 哥特式 | 简单字体 | 手写体 | 节假日 | 图案字体 | 精度像素 | 中文字体
模板下载 >> 企业门户 | 数码网络 | 休闲娱乐 | 影视音乐 | 旅游名胜 | 文化艺术 | 电子商务 | 个性展示 | 登陆导航 | Flash模板
►►您当前的位置:源码园 → IT学院 → 软件开发 → VB编程 → 文章内容

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

作者:佚名  来源:网上收集  发布时间:2005-12-8 1:31:39
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.")
]
public event DisplaySizeChangedEventHandler DisplaySizeChanged
{
add
{
eventHandler+=value;
}
remove
{
eventHandler-=value;
}
}


protected override void OnPaint(PaintEventArgs pe)
{
if(bitmap==null)
{
return;
}
Graphics g=pe.Graphics;

//转换距阵
System.Drawing.Drawing2D.Matrix transform;//距阵
if(flip.Equals(FlipModeStyle.FlipX))
{
transform=new System.Drawing.Drawing2D.Matrix(-1,0,0,1,width,0);
}
else if(flip.Equals(FlipModeStyle.FlipY))
{
transform=new System.Drawing.Drawing2D.Matrix(1,0,0,-1,0,height);
}
else if(flip.Equals(FlipModeStyle.FlipXY))
{
transform=new System.Drawing.Drawing2D.Matrix(-1,0,0,-1,width,height);
}
else
{
transform=new System.Drawing.Drawing2D.Matrix(1,0,0,1,0,0);
}
//设置转换距阵
g.Transform=transform;
g.DrawImage(bitmap,new System.Drawing.Rectangle(0,0,width,height),
0,0,bitmap.Width,bitmap.Height,
GraphicsUnit.Pixel);
//恢复绘图平面
g.ResetTransform();

}

//发出事件的方法
protected virtual void OnDisplaySizeChanged(DisplaySizeChangedEventArgs e)
{
//调用事件对象指向的方法
this.Invoke(eventHandler,new object[]
{
this,e
}
);
}

//重载方法,调用OnDisplaySizeChanged()发出事件
protected override void OnMouseDown(MouseEventArgs e)
{
width=e.X;
height=e.Y;
this.Invalidate(this.ClientRectangle);

DisplaySizeChangedEventArgs eventData=new DisplaySizeChangedEventArgs();
eventData.Width=width;
eventData.Height=height;

this.OnDisplaySizeChanged(eventData);

base.OnMouseDown(e);
}

}
}

[] [返回上一页] [打 印]
  • 上一篇文章:如何用Visual C#做组件
  • 下一篇文章:ASP.NET验证控件祥解

  • 相关文章:
  • 图象显示和翻转控件(用户自定义控件)
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 源码发布
Copyright © 2003-2009 Ymyasp.Com. All Rights Reserved .
备案序号:粤ICP备07029071号