频道直达 - 学院 - 下载 - 交易 - 截图 - 特效 - 字库 - 手册 - 排名-工具 - 繁體
设为首页
加入收藏
联系我们
建站搜索: 虚拟主机  域名注册   常用广告代码      用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发 -> Asp.Net -> 文章内容
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 通过google 赶快来赚..
· [图文] 头像-qq头像(..
· 要10G免费网络硬盘的..
· 注册码大全三
· 注册码大全十
· [图文] 梦幻背景图片..
· [图文] 卡通动物图片..
相关文章
· 我做的一个迷宫游戏(图..
· 美国互联网用户增长趋缓..
· 研究机构:钓鱼诈骗专挑有..
· Windows版本Discuz!——..
· 2005岁末BLOG程序大评点..
· Dreamweaver MX进阶教程..
· 从新浪提取上海天气的vb..
· XmlHttp异步获取网站数据..
· <展现 C#> 第一章 C#简介..
· 让自定义文件下载支持断..
图象显示和翻转控件(用户自定义控件)
作者:未知  来源:转载  发布时间:2005-7-20 10:17:35  发布人:acx

减小字体 增大字体

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

namespace ImageZoomer
{
    /// <summary>
    ///
    /// </summary>
   
    //枚举类型定义,定义图象的四种翻转方式
    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"),
        Des cription("The displayed image width.")
        ]
        public int DisplayWidth
        {
            get
            {
                return width;
            }
            set
            {
                if(value>=0)
                {
                    width=value;
                    Invalidate(this.ClientRectangle);
                }
            }
        }

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

        //图象属性
        [
        Category("ImageZoomer"),
        Des cription("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"),
        Des cription("Specify how the image will be flipped.")
        ]
        public FlipModeStyle FlipMode
        {
            get
            {
                return flip;
            }
            set
            {
                flip=value;
                this.Invalidate(this.ClientRectangle);
            }
        }

        //事件属性
        [
        Category("ImageZoomer"),
        Des cription("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);
        }

    }
}
       
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
免责申明:中国建站之家(www.jz123.cn)上的所有提供下载的软件和资源
均来源于网络,为软件或程序作者提供和网友推荐收集整理而来,仅供学习
和研究使用。如有侵犯你的版权,请立即联系我们,本站将在3个工作日内删除。
粤ICP备05092265号