友善画WinForm 皮肤包括默认控件

by admin on 2019年1月2日

好久没来果壳网,前些天捣鼓到如今就是为了把前面的肌肤控件完善好,

图片源于《五十度灰》剧照

从前也看了累累技巧小说,大多数都是和谐重写系统控件实现换肤,几乎一贯不像东日的(艾丽丝(Iris)(Iris)Skin)控件一样
添加一个组件
把系统的肌肤全换掉,我早就也是重写系统的控件,但我就喜欢瞎捣鼓,于是就最先找这地点的材料,苦于没学过底层,对windows窗口
以及信息循环机制不打听,找材料也大抵白搭了旷日持久,但最终认为自己能想到的最笨的措施实现
了后续了上下一心写的父窗口,那么窗口添加的控件就是和谐画的 而不是系统画的,

铅笔的妙处在于,可以随时随地书写记录。它不像钢笔,放久了墨水会干涸;也不似圆珠笔,天一冷就死活写不出来。作为一种古老的文具,它大概可靠,任何时候都不会辜负你创作的热忱。

先上传一张效果图:

对大五人的话,铅笔的效能只是逗留在小学抄生字的层面。而对此铅笔的主力消费人群——设计师、音乐家和文学小清新们来说,它然则吃饭的家伙,是灵感的来源,是通往心爱姑娘心中的钥匙(也恐怕是通向霸道总裁床铺的捷径)。

图片 1

不言而喻,铅笔这样一个和文学脱不了干系的文具,拿来装腔是再好不过的了。

 

铅笔装腔指南

想要用铅笔装腔,没点知识储备这是相对要穿帮的,大家先来补点干货。

▌铅笔不是只有2B

图片来自whjuren.com

笔墨纸砚店里常见的铅笔型号异常少,除了拿来涂答题卡的2B铅笔,最多也就加个适合写字的HB了。

不论2B如故HB,他们都来源于一套非洲业内,用来衡量铅笔书写颜色的浓度。

图片源于zhihu.com

这套标准里,H表示硬度,值越大则越硬越淡。B表示黑度.值越大则越软越浓。软铅笔铅质松,轻着纸面,便于修改,硬铅笔适合深远刻画细部。

6B至2H是水墨画常用的界定,平日4B或5B铅笔适合暗色调描绘,HB适合当中色调,2H或4H则宜在受光的明部描绘
(背下这句,未来就足以像艺术家一样吹牛了)。

▌一定只用木质铅笔

当代的全自动铅笔已经发展到极高的程度,每个品牌都有自我独到的出芯结构,简直像变形金刚一样!

图形来自4.bp.blogspot.com

再就是能应用不同粗细、软硬(咦我在说神马)的笔芯,知足各样绘画需求完全没有问题。

图片来源于X宝

不过!我们注意自身要转化了!但是!

自动铅笔这充满机械力量的线条总令人觉着太刻意了,全然没有木质铅笔那种浑然天成、与世无争的溯源之美。

图片源于nipic.com

再说,即便你手握红环最顶尖的600G,给人的记念也就是个苦逼绘图,价格和声调是一遍事来的(下文我会自己打脸,看官请勿见笑)。

本身要好虽然不会画画,但平生也会备上几支木质铅笔。偶尔厌烦了钢笔水笔圆珠笔的顺滑就拿它出去涂涂鸦,石墨和纸张摩擦发出的沙沙声总是令人特地快慰。

这种欣喜我就很难从活动铅笔上获取。

图表来源于douban.com

◤好了,做到上边两点,铅笔装腔能够算是入门了。上面我们来介绍几款能帮你连忙提高逼格的成品。

▌学生党必备

祥和此前当惯了贫穷学生,现在必须要毒害一下祖国将来的花朵。丢掉手上的中国和马可吧!我们来点不雷同的!

❶三菱9800绘图铅笔

图表来源gd4.alicdn.com

三菱铅笔我们也许没有水笔用的多,但质料同样卓越!扶桑原产,采用美利坚同盟国优质杉木制作。表面油漆雄厚,手感极佳。

外观像极了我们常年使用的中国铅笔,但小伙子伴凑近一看“咦,居然是三菱牌,和造电梯是同一家啊?”

本条时候你又足以大显身手了“三菱铅笔和MITSUBISHI财团可是完全没有关联的两家合作社哦!”

❷Staedtler Wopex

图形来源官网

Staedtler也毕竟一家有名德意志联邦共和国文具厂,然则这款Wopex铅笔却是充满改进与真心!

笔杆采用了出格的TPE材料,由木头、塑料及添加物制成,触感舒适且防滑卓越,摸上去有一系列似橡皮的觉得。

图形来源于pencilsforafrica.com

除此以外,笔杆可选颜色丰盛,总有符合你的这款!

❸Rhodia 橙粉红色三角铅笔

图形源于rhodiadrive.com

这支笔是自家见过唯一笔杆是紫色的铅笔,红色外皮和黄色木材的烘托让您刹那间在校友中脱颖而出!

▌设计师专用

用作一个内需大量消耗铅笔的人群,设计师们自然毫无错过这两款铅笔。

❶LYRA Groove

图表源于amazon.com

LYRA是一家创设于1806年的德意志铅笔集团,当年靠着一己之力带动了全方位北美洲的铅笔工业,他们家的铅笔和卷笔刀在北美洲随处可见,是实在的德意志百姓品牌。

Groove是方今出产的新品,表面的凹洞对于握持感提高有很大帮扶,而且笔芯够粗,对于画画的情人们来说是极好的。

❷辉柏嘉 Grip

图表来自官网

世界上一级的铅笔大厂,1761年创造。几乎各种苦逼设计师、牛逼音乐家(比如歌德、梵高)和文艺小清新皆以用上他家产品为荣。

做图形设计的小清新最爱津津乐道Grip的三角笔杆配合专利点阵的“人体艺术学”设计,握持感优秀,摆放也比六角或许圆形铅笔要来的吐鲁番久安,在奇特的行事台面上不便于滚落。

◤精晓完上边这个品牌和制品,恭喜你,铅笔装腔对你的话早已得以随手拈来。

▌总裁不来一发么?

装逼的旅途一贯都唯有更高没有最高,对于某些超凡脱俗的铅笔来说,逼格是终极极的追求。

❶Caran d’Ache 限量版

图表来源于share.photo.xuite.net

Caran
d’Ache在泰语里就是“铅笔”的意趣,限量版包含一只美洲胡桃木铅笔盒,以及4支稀有木材铅笔,和4只配套的青铜镀钯铅笔头,全球只出售2000套,买到就是赚到!

图片来源于tuhinternational.com

关于用途么,你能够在头等舱里心不在焉地用它玩数独或是填字游戏,这逼格可比看《XX商业周刊》要高得多了不是么~

❷辉柏嘉 Perfect Pencil 1761

图片源于luxurylaunches.com

二零一一年辉柏嘉为庆祝250周年华诞,展出了天下最贵的铅笔,笔盖和笔夹以铂金制作,末端还镶嵌了三颗美钻,限量发行99枝,每枝要价127,500法郎!

恩,简直就是铅笔届的双立人嘛!敛财本事一支鼎啊!

一经囊中羞涩又实在欢喜,可以考虑普通版的perfect
pencil,少了3颗美钻气质依旧这样出众,要价也唯有上边一个零头,而已。

图表源于辉柏嘉官网

❸中华双头红蓝铅笔

图片来源于X宝

假如说下边几支是铅笔世界里最豪华的主公巨星,那么这支,绝对称得上隐形的霸主!上张图我们感受一下:

图形来自nghmw.com

过多朋友或者会问为啥是这三种颜色,来,我给我们广泛一下。

首先,在军队地图上,一般都是红蓝两色代表敌我双方。而在战乱环境中,最可靠的必定是铅笔。

图片来源gucn.com

附带,在中原价值观习惯上,肉色用于对部下批复,肉色用于平级间互换,而藏黑色则用于提高汇报。

图片来自997788.com

当今我们应该领悟,为啥是红蓝铅笔了吗。

 

萌仔总结

好了,铅笔装腔的话题大家临时平息。写完那个我不由自主又败了几支,真是罪过罪过……

总的说来大家记住,逼格一定要在不经意间透表露来,没事儿拿支Pike大班出来写字儿那是2B,不是装逼。

作者:萌仔

天涯论坛网易:@萌仔睡不醒

敢说您懂生活呢?

迎接推荐给一样热爱生活的情侣们。

转载&合作,请联系我们:hedonist@mymanna.me

终日效果应该也还算勉强吧,最近本人也就写了那么些控件的鼓吹,尽管这破代码捣鼓好几天了,但代码依然混乱不堪,加上反编译了微软的片段东西,因为想赶紧出来,代码都没看,直接复制过来修改成编译不报错就形成了,

 

如今本人来说说我实现的笔触:

前题条件继续的是温馨写的FormBase
下一场重写了系统的OnControlAdded 方法,在这里为各样控件添加美化的类,

可怎么添加了?
找了好久,找到了一个可掣肘Control信息的接口:IWindowTarget
接口(具体请参考
MSDN.aspx) 微软不指出直接使用的一个类)

Control 公开并允许修改这些接口的信息,

IWindowTarget
接口有多个措施,一个是更换控件句柄的(也许应该叫设置控件句柄)
还有一个就是拍卖 Windows 音讯的OnMessage
 我要做的就是阻挠Windows 信息的重画音信,拦截下来
然后自己画,其它的仍旧丢个控件处理,(后来察觉貌似实现IMessageFilter接口也可以兑现)

好了屁话不多说了 上代码 上demo 没写完  希望大神能帮助完善下就最好了-.-!

对了
就是问个2B问题,怎么拦截所有的Form创设或者Form成立句柄时?我用IMessageFilter好像拦截不到,

唉 代码有点乱,各位将就着看呢

一对代码:

图片 2图片 3

using DotNet.Windows.Forms.Internal;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace DotNet.Windows.Forms
{
    public abstract class WindowTarget<T> : IWindowTarget
        where T : Control
    {
        private static readonly ControlStyles UserControlStyles;
        private static readonly MethodInfo SetStyleMethod;
        private static readonly MethodInfo SetStateMethod;
        private static readonly PropertyInfo CacheTextInternalProperty;
        private static readonly FieldInfo windowField;

        static WindowTarget()
        {
            UserControlStyles = ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.ContainerControl | ControlStyles.UserPaint;
            SetStyleMethod = typeof(Control).GetMethod("SetStyle",BindingFlags.Instance |BindingFlags.NonPublic);
            SetStateMethod = typeof(Control).GetMethod("SetState", BindingFlags.Instance | BindingFlags.NonPublic);
            windowField = typeof(Control).GetField("window", BindingFlags.Instance | BindingFlags.NonPublic);
            CacheTextInternalProperty = typeof(Control).GetProperty("CacheTextInternal", BindingFlags.Instance | BindingFlags.NonPublic);
        }
        private T m_Control;
        private IWindowTarget m_WindowTarget;
        private MouseState m_MouseState = MouseState.Normal;
        protected WindowTarget(T control)
        {
            m_Control = control;
            m_WindowTarget = m_Control.WindowTarget;
            m_Control.MouseUp += (o, e) => { this.MouseState = MouseState.Up; };
            m_Control.MouseEnter += (o, e) => { this.MouseState = MouseState.Move; };
            m_Control.MouseLeave += (o, e) => { this.MouseState = MouseState.Leave; };
            m_Control.MouseDown += (o, e) => { this.MouseState = MouseState.Down; };
        }
        protected virtual void SetStyle(ControlStyles styles, bool value)
        {
            SetStyleMethod.Invoke(Control, new object[] { styles, value });
        }
        private object window
        {
            get
            {
                return windowField.GetValue(Control);
            }
        }
        private bool CacheTextInternal
        {
            get
            {
                return (bool)CacheTextInternalProperty.GetValue(Control, null);
            }
            set
            {
                CacheTextInternalProperty.SetValue(Control, value, null);
            }
        }
        protected virtual void SetState(int flag, bool value)
        {
            SetStyleMethod.Invoke(Control, new object[] { flag, value });
        }
        protected T Control { get { return m_Control; } }
        protected IWindowTarget Target { get { return m_WindowTarget; } }
        protected abstract void OnPaint(DotNet.Windows.Forms.Internal.PaintEventArgs e);
        protected MouseState MouseState
        {
            get
            {
                return m_MouseState;
            }
            set
            {
                if (m_MouseState != value)
                {
                    m_MouseState = value;
                    Control.Invalidate();
                }
            }
        }
        protected virtual Image GetImage()
        {
            switch (MouseState)
            {
                case MouseState.Leave:
                case MouseState.Normal:
                    return GetNormalImage();
                case MouseState.Up:
                case MouseState.Move:
                    return GetMoveImage();
                case MouseState.Down:
                    return GetDownImage();
                default:
                    return null;
            }
        }
        protected abstract Image GetNormalImage();
        protected abstract Image GetMoveImage();
        protected abstract Image GetDownImage();
        protected void RendererBackground(Graphics g, Rectangle rect, Image backgroundImage, bool method)
        {
            if (!method)
            {
                g.DrawImage(backgroundImage, new Rectangle(rect.X + 0, rect.Y, 5, rect.Height), 0, 0, 5, backgroundImage.Height, GraphicsUnit.Pixel);
                g.DrawImage(backgroundImage, new Rectangle(rect.X + 5, rect.Y, rect.Width - 10, rect.Height), 5, 0, backgroundImage.Width - 10, backgroundImage.Height, GraphicsUnit.Pixel);
                g.DrawImage(backgroundImage, new Rectangle(rect.X + rect.Width - 5, rect.Y, 5, rect.Height), backgroundImage.Width - 5, 0, 5, backgroundImage.Height, GraphicsUnit.Pixel);
            }
            else
            {
                RendererBackground(g, rect, 5, backgroundImage);
            }
        }
        /// <summary>
        /// 渲染背景图片,使背景图片不失真
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="cut"></param>
        /// <param name="backgroundImage"></param>
        protected void RendererBackground(Graphics g, Rectangle rect, int cut, Image backgroundImage)
        {
            //左上角
            g.DrawImage(backgroundImage, new Rectangle(rect.X, rect.Y, cut, cut), 0, 0, cut, cut, GraphicsUnit.Pixel);
            //上边
            g.DrawImage(backgroundImage, new Rectangle(rect.X + cut, rect.Y, rect.Width - cut * 2, cut), cut, 0, backgroundImage.Width - cut * 2, cut, GraphicsUnit.Pixel);
            //右上角
            g.DrawImage(backgroundImage, new Rectangle(rect.X + rect.Width - cut, rect.Y, cut, cut), backgroundImage.Width - cut, 0, cut, cut, GraphicsUnit.Pixel);
            //左边
            g.DrawImage(backgroundImage, new Rectangle(rect.X, rect.Y + cut, cut, rect.Height - cut * 2), 0, cut, cut, backgroundImage.Height - cut * 2, GraphicsUnit.Pixel);
            //左下角
            g.DrawImage(backgroundImage, new Rectangle(rect.X, rect.Y + rect.Height - cut, cut, cut), 0, backgroundImage.Height - cut, cut, cut, GraphicsUnit.Pixel);
            //右边
            g.DrawImage(backgroundImage, new Rectangle(rect.X + rect.Width - cut, rect.Y + cut, cut, rect.Height - cut * 2), backgroundImage.Width - cut, cut, cut, backgroundImage.Height - cut * 2, GraphicsUnit.Pixel);
            //右下角
            g.DrawImage(backgroundImage, new Rectangle(rect.X + rect.Width - cut, rect.Y + rect.Height - cut, cut, cut), backgroundImage.Width - cut, backgroundImage.Height - cut, cut, cut, GraphicsUnit.Pixel);
            //下边
            g.DrawImage(backgroundImage, new Rectangle(rect.X + cut, rect.Y + rect.Height - cut, rect.Width - cut * 2, cut), cut, backgroundImage.Height - cut, backgroundImage.Width - cut * 2, cut, GraphicsUnit.Pixel);
            //平铺中间
            g.DrawImage(backgroundImage, new Rectangle(rect.X + cut, rect.Y + cut, rect.Width - cut * 2, rect.Height - cut * 2), cut, cut, backgroundImage.Width - cut * 2, backgroundImage.Height - cut * 2, GraphicsUnit.Pixel);
        }
        #region IWindowTarget 成员
        void IWindowTarget.OnHandleChange(IntPtr newHandle)
        {
            Target.OnHandleChange(newHandle);
        }
        private BufferedGraphicsContext BufferContext
        {
            get
            {
                return BufferedGraphicsManager.Current;
            }
        }
        internal static IntPtr SetUpPalette(IntPtr dc, bool force, bool realizePalette)
        {
            IntPtr halftonePalette = Graphics.GetHalftonePalette();
            IntPtr ptr2 = SafeNativeMethods.SelectPalette(new HandleRef(null, dc), new HandleRef(null, halftonePalette), force ? 0 : 1);
            if ((ptr2 != IntPtr.Zero) && realizePalette)
            {
                SafeNativeMethods.RealizePalette(new HandleRef(null, dc));
            }
            return ptr2;
        }
        private void WmPaint(ref  Message m)
        {
            bool flag = true;
            IntPtr zero = IntPtr.Zero;
            NativeMethods.PAINTSTRUCT lpPaint = new NativeMethods.PAINTSTRUCT();
            bool flag2 = false;
            try
            {
                IntPtr wParam;
                Rectangle clientRectangle;
                if (m.WParam == IntPtr.Zero)
                {
                    zero = Control.Handle;
                    wParam = UnsafeNativeMethods.BeginPaint(new HandleRef(this, zero), ref lpPaint);
                    flag2 = true;
                    clientRectangle = new Rectangle(lpPaint.rcPaint_left, lpPaint.rcPaint_top, lpPaint.rcPaint_right - lpPaint.rcPaint_left, lpPaint.rcPaint_bottom - lpPaint.rcPaint_top);
                }
                else
                {
                    wParam = m.WParam;
                    clientRectangle = Control.ClientRectangle;
                }
                if (!flag || ((clientRectangle.Width > 0) && (clientRectangle.Height > 0)))
                {
                    IntPtr handle = IntPtr.Zero;
                    BufferedGraphics graphics = null;
                    DotNet.Windows.Forms.Internal.PaintEventArgs e = null;
                    System.Drawing.Drawing2D.GraphicsState gstate = null;
                    try
                    {
                        if (flag || (m.WParam == IntPtr.Zero))
                        {
                            handle = SetUpPalette(wParam, false, false);
                        }
                        if (flag)
                        {
                            try
                            {
                                graphics = this.BufferContext.Allocate(wParam, Control.ClientRectangle);
                            }
                            catch (Exception exception)
                            {
                                if (ClientUtils.IsCriticalException(exception))
                                {
                                    throw;
                                }
                                flag = false;
                            }
                        }
                        if (graphics != null)
                        {
                            graphics.Graphics.SetClip(clientRectangle);
                            e = new DotNet.Windows.Forms.Internal.PaintEventArgs(graphics.Graphics, clientRectangle);
                            gstate = e.Graphics.Save();
                        }
                        else
                        {
                            e = new DotNet.Windows.Forms.Internal.PaintEventArgs(wParam, clientRectangle);
                        }
                        using (e)
                        {
                            try
                            {
                                if (((m.WParam == IntPtr.Zero) && true) || flag)
                                {
                                    this.PaintWithErrorHandling(e, 1);
                                }
                            }
                            finally
                            {
                                if (gstate != null)
                                {
                                    e.Graphics.Restore(gstate);
                                }
                                else
                                {
                                    e.ResetGraphics();
                                }
                            }
                            this.PaintWithErrorHandling(e, 2);
                            if (graphics != null)
                            {
                                graphics.Render();
                            }
                        }
                    }
                    finally
                    {
                        if (handle != IntPtr.Zero)
                        {
                            SafeNativeMethods.SelectPalette(new HandleRef(null, wParam), new HandleRef(null, handle), 0);
                        }
                        if (graphics != null)
                        {
                            graphics.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (flag2)
                {
                    UnsafeNativeMethods.EndPaint(new HandleRef(this, zero), ref lpPaint);
                }
            }
        }
        protected virtual void OnPaintBackground(DotNet.Windows.Forms.Internal.PaintEventArgs pevent)
        {
            NativeMethods.RECT rect = new NativeMethods.RECT();
            UnsafeNativeMethods.GetClientRect(new HandleRef(this.window, Control.Handle), ref rect);
            this.PaintBackground(pevent, new Rectangle(rect.left, rect.top, rect.right, rect.bottom));
        }
        internal void PaintBackground(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle)
        {
            this.PaintBackground(e, rectangle, Control.BackColor, Point.Empty);
        }

        internal void PaintBackground(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle, System.Drawing.Color backColor)
        {
            this.PaintBackground(e, rectangle, backColor, Point.Empty);
        }
        private bool RenderColorTransparent(System.Drawing.Color c)
        {
            return ((c.A < 0xff));
        }
        internal void PaintTransparentBackground(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle)
        {
            this.PaintTransparentBackground(e, rectangle, null);
        }
        internal static bool IsImageTransparent(Image backgroundImage)
        {
            return ((backgroundImage != null) && ((backgroundImage.Flags & 2) > 0));
        }
        internal static Rectangle CalculateBackgroundImageRectangle(Rectangle bounds, Image backgroundImage, ImageLayout imageLayout)
        {
            Rectangle rectangle = bounds;
            if (backgroundImage != null)
            {
                switch (imageLayout)
                {
                    case ImageLayout.None:
                        rectangle.Size = backgroundImage.Size;
                        return rectangle;

                    case ImageLayout.Tile:
                        return rectangle;

                    case ImageLayout.Center:
                        {
                            rectangle.Size = backgroundImage.Size;
                            Size size = bounds.Size;
                            if (size.Width > rectangle.Width)
                            {
                                rectangle.X = (size.Width - rectangle.Width) / 2;
                            }
                            if (size.Height > rectangle.Height)
                            {
                                rectangle.Y = (size.Height - rectangle.Height) / 2;
                            }
                            return rectangle;
                        }
                    case ImageLayout.Stretch:
                        rectangle.Size = bounds.Size;
                        return rectangle;

                    case ImageLayout.Zoom:
                        {
                            Size size2 = backgroundImage.Size;
                            float num = ((float)bounds.Width) / ((float)size2.Width);
                            float num2 = ((float)bounds.Height) / ((float)size2.Height);
                            if (num >= num2)
                            {
                                rectangle.Height = bounds.Height;
                                rectangle.Width = (int)((size2.Width * num2) + 0.5);
                                if (bounds.X >= 0)
                                {
                                    rectangle.X = (bounds.Width - rectangle.Width) / 2;
                                }
                                return rectangle;
                            }
                            rectangle.Width = bounds.Width;
                            rectangle.Height = (int)((size2.Height * num) + 0.5);
                            if (bounds.Y >= 0)
                            {
                                rectangle.Y = (bounds.Height - rectangle.Height) / 2;
                            }
                            return rectangle;
                        }
                }
            }
            return rectangle;
        }
        internal static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (backgroundImageLayout == ImageLayout.Tile)
            {
                using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
                {
                    if (scrollOffset != Point.Empty)
                    {
                        Matrix transform = brush.Transform;
                        transform.Translate((float)scrollOffset.X, (float)scrollOffset.Y);
                        brush.Transform = transform;
                    }
                    g.FillRectangle(brush, clipRect);
                    return;
                }
            }
            Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
            if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
            {
                rect.X += clipRect.Width - rect.Width;
            }
            using (SolidBrush brush2 = new SolidBrush(backColor))
            {
                g.FillRectangle(brush2, clipRect);
            }
            if (!clipRect.Contains(rect))
            {
                if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
                {
                    rect.Intersect(clipRect);
                    g.DrawImage(backgroundImage, rect);
                }
                else if (backgroundImageLayout == ImageLayout.None)
                {
                    rect.Offset(clipRect.Location);
                    Rectangle destRect = rect;
                    destRect.Intersect(clipRect);
                    Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
                    g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
                }
                else
                {
                    Rectangle rectangle4 = rect;
                    rectangle4.Intersect(clipRect);
                    Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
                    g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
                }
            }
            else
            {
                ImageAttributes imageAttr = new ImageAttributes();
                imageAttr.SetWrapMode(WrapMode.TileFlipXY);
                g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
                imageAttr.Dispose();
            }
        }
        internal void PaintTransparentBackground(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle, System.Drawing.Region transparentRegion)
        {
            Graphics g = e.Graphics;
            Control parentInternal = Control.Parent;
            if (parentInternal != null)
            {
                if (Application.RenderWithVisualStyles) // parentInternal.RenderTransparencyWithVisualStyles)
                {
                    System.Drawing.Drawing2D.GraphicsState gstate = null;
                    if (transparentRegion != null)
                    {
                        gstate = g.Save();
                    }
                    try
                    {
                        if (transparentRegion != null)
                        {
                            g.Clip = transparentRegion;
                        }
                        ButtonRenderer.DrawParentBackground(g, rectangle, Control);
                        return;
                    }
                    finally
                    {
                        if (gstate != null)
                        {
                            g.Restore(gstate);
                        }
                    }
                }
                Rectangle rectangle2 = new Rectangle(-Control.Left, -Control.Top, parentInternal.Width, parentInternal.Height);
                Rectangle clipRect = new Rectangle(rectangle.Left + Control.Left, rectangle.Top + Control.Top, rectangle.Width, rectangle.Height);
                using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(g))
                {
                    graphics2.DeviceContext.TranslateTransform(-Control.Left, -Control.Top);
                    using (DotNet.Windows.Forms.Internal.PaintEventArgs args = new DotNet.Windows.Forms.Internal.PaintEventArgs(graphics2.GetHdc(), clipRect))
                    {
                        if (transparentRegion != null)
                        {
                            args.Graphics.Clip = transparentRegion;
                            args.Graphics.TranslateClip(-rectangle2.X, -rectangle2.Y);
                        }
                        try
                        {
                            //this.InvokePaintBackground(parentInternal, args);
                            //this.InvokePaint(parentInternal, args);
                        }
                        finally
                        {
                            if (transparentRegion != null)
                            {
                                args.Graphics.TranslateClip(rectangle2.X, rectangle2.Y);
                            }
                        }
                    }
                    return;
                }
            }
            g.FillRectangle(SystemBrushes.Control, rectangle);
        }
        internal void PaintBackground(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle, System.Drawing.Color backColor, Point scrollOffset)
        {
            backColor = Color.Transparent;
            //ControlStyles.SupportsTransparentBackColor;
            this.PaintTransparentBackground(e, rectangle);
            //if (this.RenderColorTransparent(backColor))
            //{
            //    this.PaintTransparentBackground(e, rectangle);
            //}
            bool flag = ((Control is FormBase) || (this is MdiClient)) && Control.IsMirrored;
            if (((Control.BackgroundImage != null) && !SystemInformation.HighContrast) && !flag)
            {
                if ((Control.BackgroundImageLayout == ImageLayout.Tile) && IsImageTransparent(Control.BackgroundImage))
                {
                    PaintTransparentBackground(e, rectangle);
                }
                Point autoScrollPosition = scrollOffset;
                if ((Control is ScrollableControl) && (autoScrollPosition != Point.Empty))
                {
                    autoScrollPosition = ((ScrollableControl)(Control)Control).AutoScrollPosition;
                }
                if (IsImageTransparent(Control.BackgroundImage))
                {
                    PaintBackColor(e, rectangle, backColor);
                }
                DrawBackgroundImage(e.Graphics, Control.BackgroundImage, backColor, Control.BackgroundImageLayout, Control.ClientRectangle, rectangle, autoScrollPosition, Control.RightToLeft);
            }
            else
            {
                PaintBackColor(e, rectangle, backColor);
            }
        }
        private static void PaintBackColor(DotNet.Windows.Forms.Internal.PaintEventArgs e, Rectangle rectangle, System.Drawing.Color backColor)
        {
            System.Drawing.Color nearestColor = backColor;
            if (nearestColor.A == 0xff)
            {
                using (WindowsGraphics graphics = ((e.HDC != IntPtr.Zero) && ((short)Screen.PrimaryScreen.BitsPerPixel > 8)) ? WindowsGraphics.FromHdc(e.HDC) : WindowsGraphics.FromGraphics(e.Graphics))
                {
                    nearestColor = graphics.GetNearestColor(nearestColor);
                    using (WindowsBrush brush = new WindowsSolidBrush(graphics.DeviceContext, nearestColor))
                    {
                        graphics.FillRectangle(brush, rectangle);
                    }
                    return;
                }
            }
            if (nearestColor.A > 0)
            {
                using (Brush brush2 = new SolidBrush(nearestColor))
                {
                    e.Graphics.FillRectangle(brush2, rectangle);
                }
            }
        }
        private void PaintWithErrorHandling(DotNet.Windows.Forms.Internal.PaintEventArgs e, short layer)
        {
            try
            {
                this.CacheTextInternal = true;
                bool flag = true;
                try
                {
                    switch (layer)
                    {
                        case 1:
                            this.OnPaintBackground(e);
                            break;
                        case 2:
                            this.OnPaint(e);
                            break;
                    }
                    flag = false;
                }
                finally
                {
                    if (flag)
                    {
                        this.SetState(0x400000, true);
                        Control.Invalidate();
                    }
                }
            }
            finally
            {
                this.CacheTextInternal = false;
            }
        }
        void IWindowTarget.OnMessage(ref Message m)
        {
            if (m.Msg == 15)
            {
                WmPaint(ref m);
                return;
            }
            Target.OnMessage(ref m);
        }

        #endregion
    }
}

View Code

 

 

 

http://files.cnblogs.com/dotnet-org-cn/DotNet.Framework.rar

 

末段打个小广告:中国.NET协会(http://www.dotnet.org.cn
腾讯企鹅群:45132984图片 4
和讯地址:http://http://www.cnblogs.com/dotnet-org-cn
     国内唯一一个以非盈利的.NET协会,致力打造国内所有权威性、价值性的.NET社团。

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图