示例#1
0
        public override void PaintValue(PaintValueEventArgs e)
        {
            string   text = e.Value.ToString();
            Bitmap   bp   = new Bitmap(e.Bounds.Width, e.Bounds.Height);
            Graphics g    = Graphics.FromImage(bp);

            Brush bg, fg;

            bg = SystemBrushes.Window;
            fg = SystemBrushes.WindowText;

            g.FillRectangle(SystemBrushes.Highlight, e.Bounds);

            IntPtr  hdc = g.GetHdc();
            GDIFont gf  = new GDIFont(text, 9);
            int     a   = 0;
            IntPtr  res = NativeGdi32Api.SelectObject(hdc, gf.hFont);

            NativeGdi32Api.SetTextColor(hdc, ColorTranslator.ToWin32(SystemColors.Window));
            NativeGdi32Api.SetBkMode(hdc, 0);
            NativeUser32Api.TabbedTextOut(hdc, 1, 1, "abc", 3, 0, ref a, 0);
            NativeGdi32Api.SelectObject(hdc, res);
            gf.Dispose();
            g.ReleaseHdc(hdc);
            e.Graphics.DrawImage(bp, e.Bounds.Left, e.Bounds.Top);

            //	e.Graphics.DrawString ("abc",new Font (text,10f),SystemBrushes.Window,3,0);
        }
示例#2
0
        public void SetBrushOrg(int x, int y)
        {
            POINTAPI p;

            p.X = 0;
            p.Y = 0;
            NativeGdi32Api.SetBrushOrgEx(mhDC, x, y, ref p);
        }
示例#3
0
        public GDIBrush(IntPtr hBMP_Pattern)
        {
            hBrush = NativeGdi32Api.CreatePatternBrush(hBMP_Pattern);
            //if (hBrush==(IntPtr)0)
            //Puzzle.Debug.Debugger.WriteLine ("Failed to create brush with color : {0}",color.ToString());

            Create();
        }
示例#4
0
 protected override void Destroy()
 {
     if (hFont != (IntPtr)0)
     {
         NativeGdi32Api.DeleteObject(hFont);
     }
     base.Destroy();
     hFont = (IntPtr)0;
 }
示例#5
0
 protected override void Destroy()
 {
     if (hPen != (IntPtr)0)
     {
         NativeGdi32Api.DeleteObject(hPen);
     }
     base.Destroy();
     hPen = (IntPtr)0;
 }
示例#6
0
        //public void SetPixel(GDIColor color,int x,int y)
        //{
        //    NativeGdi32Api.SetPixel(_destDC, x, y, color.NativeColor);
        //}

        //public GDIColor GetPixel(int x, int y)
        //{
        //    int cl = NativeGdi32Api.GetPixel(_destDC,x,y);
        //    GDIColor color = new GDIColor(cl);
        //    return color;
        //}

        protected override void Destroy()
        {
            if (_hBmp != (IntPtr)0)
            {
                NativeGdi32Api.DeleteObject(_hBmp);
                NativeGdi32Api.DeleteDC(_destDC);
            }

            base.Destroy();
            _hBmp = (IntPtr)0;
        }
示例#7
0
        public void DrawLine(GDIPen pen, Point p1, Point p2)
        {
            IntPtr   oldpen = NativeGdi32Api.SelectObject(mhDC, pen.hPen);
            POINTAPI gp;

            gp.X = 0;
            gp.Y = 0;
            NativeGdi32Api.MoveToEx(mhDC, p1.X, p1.Y, ref gp);
            NativeGdi32Api.LineTo(mhDC, p2.X, p2.Y);
            IntPtr crap = NativeGdi32Api.SelectObject(mhDC, oldpen);
        }
示例#8
0
        protected override void Destroy()
        {
            //only destroy if brush is created by us
            if (!mSystemBrush)
            {
                if (hBrush != (IntPtr)0)
                {
                    NativeGdi32Api.DeleteObject(hBrush);
                }
            }

            base.Destroy();
            hBrush = (IntPtr)0;
        }
示例#9
0
        public GDIBitmap(string filename)
        {
            FreeImage img    = new FreeImage(filename);
            IntPtr    deskDC = NativeUser32Api.GetDC(new IntPtr(0));

            _destDC = NativeGdi32Api.CreateCompatibleDC(deskDC);
            IntPtr oldObj = NativeGdi32Api.SelectObject(_destDC, _hBmp);

            _hBmp = NativeGdi32Api.CreateCompatibleBitmap(_destDC, img.Width, img.Height);
            img.PaintToDevice(_destDC, 0, 0, img.Width, img.Height, 0, 0, 0, img.Height, 0);
            NativeGdi32Api.SelectObject(_destDC, oldObj);

            _width  = img.Width;
            _height = img.Height;

            NativeGdi32Api.DeleteDC(deskDC);
            //NativeGdi32Api.DeleteDC(destDC);
            img.Dispose();
        }
示例#10
0
        public ICollection EnumFonts()
        {
            Bitmap   bmp = new Bitmap(10, 10);
            Graphics g   = Graphics.FromImage(bmp);

            IntPtr hDC = g.GetHdc();

            Fonts = new Hashtable();
            LogFont lf = new LogFont();

            lf.lfCharSet = 1;
            FONTENUMPROC callback = new FONTENUMPROC(this.CallbackFunc);

            NativeGdi32Api.EnumFontFamiliesEx(hDC, lf, callback, 0, 0);

            g.ReleaseHdc(hDC);
            g.Dispose();
            bmp.Dispose();
            return(Fonts.Keys);
        }
示例#11
0
        protected void Init(int width, int height, IntPtr hdc)
        {
            mWidth  = width;
            mHeight = height;
            mhDC    = NativeGdi32Api.CreateCompatibleDC(hdc);

            mhBMP = NativeGdi32Api.CreateCompatibleBitmap(hdc, width, height);

            IntPtr ret = NativeGdi32Api.SelectObject(mhDC, mhBMP);

            _OldBmp = ret;

            if (mhDC == (IntPtr)0)
            {
                MessageBox.Show("hDC creation FAILED!!");
            }

            if (mhDC == (IntPtr)0)
            {
                MessageBox.Show("hBMP creation FAILED!!");
            }
        }
示例#12
0
        protected override void Destroy()
        {
            if (_OldBmp != IntPtr.Zero)
            {
                NativeGdi32Api.SelectObject(this.hDC, _OldBmp);
            }

            if (_OldFont != IntPtr.Zero)
            {
                NativeGdi32Api.SelectObject(this.hDC, _OldFont);
            }

            if (_OldPen != IntPtr.Zero)
            {
                NativeGdi32Api.SelectObject(this.hDC, _OldPen);
            }

            if (_OldBrush != IntPtr.Zero)
            {
                NativeGdi32Api.SelectObject(this.hDC, _OldBrush);
            }

            if (mhBMP != (IntPtr)0)
            {
                NativeGdi32Api.DeleteObject(mhBMP);
            }

            if (mhDC != (IntPtr)0)
            {
                NativeGdi32Api.DeleteDC(mhDC);
            }

            mhBMP = (IntPtr)0;
            mhDC  = (IntPtr)0;

            base.Destroy();
        }
示例#13
0
        protected void Init(string fontname, float size, bool bold, bool italic, bool underline, bool strikethrough)
        {
            FontName      = fontname;
            Size          = size;
            Bold          = bold;
            Italic        = italic;
            Underline     = underline;
            Strikethrough = strikethrough;

            LogFont tFont = new LogFont();

            tFont.lfItalic    = (byte)(this.Italic ? 1 : 0);
            tFont.lfStrikeOut = (byte)(this.Strikethrough ? 1 : 0);
            tFont.lfUnderline = (byte)(this.Underline ? 1 : 0);
            tFont.lfWeight    = this.Bold ? 700 : 400;
            tFont.lfWidth     = 0;
            tFont.lfHeight    = (int)(-this.Size * 1.3333333333333);
            tFont.lfCharSet   = 1;

            tFont.lfFaceName = this.FontName;


            hFont = NativeGdi32Api.CreateFontIndirect(tFont);
        }
示例#14
0
 public GDIPen(Color color, int width)
 {
     hPen = NativeGdi32Api.CreatePen(0, width, NativeUser32Api.ColorToInt(color));
     Create();
 }
示例#15
0
 public GDIBrush(int Style, Color color)
 {
     hBrush = NativeGdi32Api.CreateHatchBrush(Style, NativeUser32Api.ColorToInt(color));
     Create();
 }
示例#16
0
        private void LB_DrawItem(object sender, DrawItemEventArgs e)
        {
            bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            if (e.Index == -1)
            {
                return;
            }


            object li = FontListbox.Items[e.Index];
            string text = li.ToString();
            Brush  bg, fg;

            if (selected)
            {
                bg = SystemBrushes.Highlight;
                fg = SystemBrushes.HighlightText;
                //fg=Brushes.Black;
            }
            else
            {
                bg = SystemBrushes.Window;
                fg = SystemBrushes.WindowText;
            }

            //e.Graphics.FillRectangle (SystemBrushes.Window,0,e.Bounds.Top,e.Bounds.Width ,FontListbox.ItemHeight);
            if (selected)
            {
                int ofs = 37;
                e.Graphics.FillRectangle(SystemBrushes.Window, new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs, FontListbox.ItemHeight));
                e.Graphics.FillRectangle(SystemBrushes.Highlight, new Rectangle(ofs + 1, e.Bounds.Top + 1, e.Bounds.Width - ofs - 2, FontListbox.ItemHeight - 2));
                System.Windows.Forms.ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs, FontListbox.ItemHeight));
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Window, 0, e.Bounds.Top, e.Bounds.Width, FontListbox.ItemHeight);
            }


            e.Graphics.DrawString(text, e.Font, fg, 38, e.Bounds.Top + 4);

            e.Graphics.SetClip(new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));


            e.Graphics.FillRectangle(SystemBrushes.Highlight, new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));

            IntPtr  hdc = e.Graphics.GetHdc();
            GDIFont gf  = new GDIFont(text, 9);
            int     a   = 0;
            IntPtr  res = NativeGdi32Api.SelectObject(hdc, gf.hFont);

            NativeGdi32Api.SetTextColor(hdc, ColorTranslator.ToWin32(SystemColors.Window));
            NativeGdi32Api.SetBkMode(hdc, 0);
            NativeUser32Api.TabbedTextOut(hdc, 3, e.Bounds.Top + 5, "abc", 3, 0, ref a, 0);
            NativeGdi32Api.SelectObject(hdc, res);
            gf.Dispose();
            e.Graphics.ReleaseHdc(hdc);
            e.Graphics.DrawRectangle(Pens.Black, new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));
            e.Graphics.ResetClip();
        }
示例#17
0
        //---------------------------------------
        //render methods ,
        //render to dc ,
        //render to control
        //render to gdisurface

        public void RenderTo(IntPtr hdc, int x, int y)
        {
            NativeGdi32Api.BitBlt(hdc, x, y, mWidth, mHeight, mhDC, 0, 0, (int)GDIRop.SrcCopy);
        }
示例#18
0
 public GDIBrush(Bitmap pattern)
 {
     hBrush = NativeGdi32Api.CreatePatternBrush(pattern.GetHbitmap());
     Create();
 }
示例#19
0
 public void RenderTo(GDISurface target, int SourceX, int SourceY, int Width, int Height, int DestX, int DestY)
 {
     NativeGdi32Api.BitBlt(target.hDC, DestX, DestY, Width, Height, this.hDC, SourceX, SourceY, (int)GDIRop.SrcCopy);
 }
示例#20
0
 public void Flush()
 {
     NativeGdi32Api.GdiFlush();
 }
示例#21
0
 public GDIBrush(Color color)
 {
     hBrush = NativeGdi32Api.CreateSolidBrush(NativeUser32Api.ColorToInt(color));
     Create();
 }