已有57人关注
树形控件水平翻转显示
发表在C#图书答疑 2012-01-18
是否精华
版块置顶:
你好,我是少数民族读者,民文是从右向左写的,树形控件水平翻转展开后才能符合本民族文字树形格式显示的,这个问题怎么解决请各位专家指教一下好吗?QQ499473327,thajim@126.com
分享到:
精彩评论 1
东方_mrkj
学分:0 LV1
2012-01-19
沙发
读者你好:
   下面有一段关于控件翻转的代码,可以参考一下:

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"),
        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);
        }

    }
}
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照