莫是才出2B才是铅笔

by admin on 2018年9月8日

好老无来博客园,今天挑到现在即使是为将前的皮控件完善好,

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

前面为看了成千上万技巧文章,大多数都是温馨还写系统控件实现换肤,几乎从来不像东日的(IrisSkin)控件一样
添加一个组件
把系统的皮都变掉,我已经为是又写系统的控件,但自我哪怕喜欢瞎捣鼓,于是就起摸索这点的素材,苦于没有学过根,对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

三菱铅笔大家或许无水笔用底几近,但人同样出色!日本原产,采用美国上流杉木制作。表面油漆厚实,手感极佳。

外观像极了我们常年使用的炎黄铅笔,但青少年伴凑近平圈“咦,居然是三菱牌,和造电梯是同家呢?”

是时节你同时足以大显身手了“三菱铅笔和三菱财团但了没干之一定量贱合作社哦!”

❷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

2011年辉柏嘉为庆祝250周年华诞,展出了举世最为贵的铅笔,笔盖和笔夹以铂金制作,末端还嵌了三粒美钻,限量发行99杆,每枝要价127,500港币!

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

一旦囊中羞涩又实在好,可以设想普通版的perfect
pencil,少了3发美研气质还是这样出众,要价也只有点一个零头,而已。

图形来源于辉柏嘉官网

❸中华双头红蓝铅笔

图片源于X宝

假如说上面几乎支付是铅笔世界里最为华丽的天皇巨星,那么就出,绝对称得上隐形的霸主!上张图大家感受一下:

图片来自nghmw.com

成千上万对象可能会见问为什么是这有限种颜色,来,我深受大家常见一下。

首先,在军队地图及,一般都是吉祥蓝两质量代表敌我双方。而以战乱条件受到,最可靠的得是铅笔。

图形来源于gucn.com

说不上,在中原民俗习惯及,红色用于对下级批复,蓝色用于平级间交流,而黑色则用于提高反映。

图来源997788.com

现今大家应该明了,为什么是红蓝铅笔了咔嚓。

 

萌仔总结

吓了,铅笔装腔的话题我们小停止。写了这些我禁不住以散了几开支,真是罪过罪过……

总的说来大家记住,逼格一定要是在不留意间流露出来,没事儿拿支万宝龙大班出来写字儿那是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地图