文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一、抽象类SkinFormRenderer

一、抽象类SkinFormRenderer

时间:2010-08-26  来源:orsca

SkinFormRenderer类是一个非常重要的类,重写它里边的方法,就能得到新的窗体皮肤。

它包含几个抽象方法:

public abstract Region CreateRegion(SkinForm form);创建一块儿绘图区域给SkinForm使用。

------------

protected abstract void OnRenderSkinFormCaption(SkinFormCaptionRenderEventArgs e);绘制窗体的标题栏

protected abstract void OnRenderSkinFormBorder(SkinFormBorderRenderEventArgs e);绘制窗体的边框

protected abstract void OnRenderSkinFormBackground(SkinFormBackgroundRenderEventArgs e);绘制窗体背景。

protected abstract void OnRenderSkinFormControlBox(SkinFormControlBoxRenderEventArgs e);绘制窗体的控件。

从总体上说,根据命名规则,可以横线下的方法都是相应事件的处理函数。

现在我们看看这个抽象函数中相应的参数吧。

  1、SkinFormCaptionRenderEventArgs

  继承于PaintEventArgs消息类,包含了窗体绘制的信息:指定的图形和剪辑矩形框

并在该类外部定义了相应的事件处理函数的委托

public delegate void SkinFormCaptionRenderEventHandler( object sender, SkinFormCaptionRenderEventArgs e);

2、SkinFormBorderRenderEventArgs

该消息类同样继承于PaintEventArgs

并在类的外部定义了相应事件处理函数的委托:public delegate void SkinFormBorderRenderEventHandler( object sender,SkinFormBorderRenderEventArgs e);

下面两个相同,仅是添加了具有针对性的参数,用于在绘制过程中传递相应的值。

粘上全部SkinFormRenderer的代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Security.Permissions;

namespace CSharpWin
{
    /* 作者:Starts_2000
     * 日期:2009-09-20
     * 网站:http://www.csharpwin.com CS 程序员之窗。
     * 你可以免费使用或修改以下代码,但请保留版权信息。
     * 具体请查看 CS程序员之窗开源协议(http://www.csharpwin.com/csol.html)。
     */

    public abstract class SkinFormRenderer
    {
        #region Fields

        private EventHandlerList _events;

        private static readonly object EventRenderSkinFormCaption = new object();
        private static readonly object EventRenderSkinFormBorder = new object();
        private static readonly object EventRenderSkinFormBackground = new object();
        private static readonly object EventRenderSkinFormControlBox = new object();

        #endregion

        #region Constructors

        protected SkinFormRenderer()
        {
        }

        #endregion

        #region Properties

        protected EventHandlerList Events
        {
            get
            {
                if (_events == null)
                {
                    _events = new EventHandlerList();
                }
                return _events;
            }
        }

        #endregion

        #region Events

        public event SkinFormCaptionRenderEventHandler RenderSkinFormCaption
        {
            add { AddHandler(EventRenderSkinFormCaption, value); }
            remove { RemoveHandler(EventRenderSkinFormCaption, value); }
        }

        public event SkinFormBorderRenderEventHandler RenderSkinFormBorder
        {
            add { AddHandler(EventRenderSkinFormBorder, value); }
            remove { RemoveHandler(EventRenderSkinFormBorder, value); }
        }

        public event SkinFormBackgroundRenderEventHandler RenderSkinFormBackground
        {
            add { AddHandler(EventRenderSkinFormBackground, value); }
            remove { RemoveHandler(EventRenderSkinFormBackground, value); }
        }

        public event SkinFormControlBoxRenderEventHandler RenderSkinFormControlBox
        {
            add { AddHandler(EventRenderSkinFormControlBox, value); }
            remove { RemoveHandler(EventRenderSkinFormControlBox, value); }
        }

        #endregion

        #region Public Methods

        public abstract Region CreateRegion(SkinForm form);

        public abstract void InitSkinForm(SkinForm  form);

        public void DrawSkinFormCaption(
            SkinFormCaptionRenderEventArgs e)
        {
            OnRenderSkinFormCaption(e);
            SkinFormCaptionRenderEventHandler handle =
                Events[EventRenderSkinFormCaption]
                as SkinFormCaptionRenderEventHandler;
            if (handle != null)
            {
                handle(this, e);
            }
        }


        public void DrawSkinFormBorder(
            SkinFormBorderRenderEventArgs e)
        {
            OnRenderSkinFormBorder(e);
            SkinFormBorderRenderEventHandler handle =
                Events[EventRenderSkinFormBorder]
                as SkinFormBorderRenderEventHandler;
            if (handle != null)
            {
                handle(this, e);
            }
        }


        public void DrawSkinFormBackground(
            SkinFormBackgroundRenderEventArgs e)
        {
            OnRenderSkinFormBackground(e);
            SkinFormBackgroundRenderEventHandler handle =
                Events[EventRenderSkinFormBackground]
                as SkinFormBackgroundRenderEventHandler;
            if (handle != null)
            {
                handle(this, e);
            }
        }

        public void DrawSkinFormControlBox(
            SkinFormControlBoxRenderEventArgs e)
        {
            OnRenderSkinFormControlBox(e);
            SkinFormControlBoxRenderEventHandler handle =
                Events[EventRenderSkinFormControlBox]
                as SkinFormControlBoxRenderEventHandler;
            if (handle != null)
            {
                handle(this, e);
            }
        }

        #endregion

        #region Protected Render Methods

        protected abstract void OnRenderSkinFormCaption(
            SkinFormCaptionRenderEventArgs e);

        protected abstract void OnRenderSkinFormBorder(
            SkinFormBorderRenderEventArgs e);

        protected abstract void OnRenderSkinFormBackground(
            SkinFormBackgroundRenderEventArgs e);

        protected abstract void OnRenderSkinFormControlBox(
            SkinFormControlBoxRenderEventArgs e);

        #endregion

        #region Protected Methods

        [UIPermission(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
        protected void AddHandler(object key, Delegate value)
        {
            Events.AddHandler(key, value);
        }

        [UIPermission(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
        protected void RemoveHandler(object key, Delegate value)
        {
            Events.RemoveHandler(key, value);
        }

        #endregion
    }
}

 

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载