Beispiel #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);
        }
Beispiel #2
0
        public void RenderToControl(int x, int y)
        {
            IntPtr hdc = NativeUser32Api.ControlDC(Control);

            RenderTo(hdc, x, y);
            NativeUser32Api.ReleaseDC(Control.Handle, hdc);
        }
Beispiel #3
0
        public GDISurface(int width, int height)
        {
            // added: 31/01/06
            //TODO: test it
            IntPtr deskDC = NativeUser32Api.GetDC(new IntPtr(0));

            Init(width, height, deskDC);
            Create();
        }
Beispiel #4
0
 protected void Deactivate()
 {
     NativeUser32Api.SendMessage(this.Handle, WM_MBUTTONUP, 0, 0);
     Active = false;
     tmrFeedback.Enabled = false;
     this.Hide();
     onEndScroll(new EventArgs());
     this.Parent.Focus();
 }
Beispiel #5
0
        /// <summary>
        /// Sets the image list for the TreeView to the system image list.
        /// </summary>
        /// <param name="tvwHandle">The window handle of the TreeView control</param>
        public static void SetTVImageList(IntPtr tvwHandle)
        {
            InitImageList();
            Int32 hRes = NativeUser32Api.SendMessage(tvwHandle, TVM_SETIMAGELIST, TVSIL_NORMAL, m_pImgHandle);

            if (hRes != 0)
            {
                Marshal.ThrowExceptionForHR(hRes);
            }
        }
Beispiel #6
0
        public static bool DrawControl(Control control, Bitmap b)
        {
            Graphics g   = Graphics.FromImage(b);
            IntPtr   hdc = g.GetHdc();
            int      i   = NativeUser32Api.SendMessage(control.Handle, (int)WindowMessage.WM_PRINT, (int)hdc, (int)(WMPrintFlags.PRF_CLIENT | WMPrintFlags.PRF_ERASEBKGND));

            g.ReleaseHdc(hdc);
            g.Dispose();
            return(i != 0);
        }
Beispiel #7
0
        public void InvertRect(int x, int y, int width, int height)
        {
            RECTAPI gr;

            gr.Top    = y;
            gr.Left   = x;
            gr.Right  = width + x;
            gr.Bottom = height + y;

            NativeUser32Api.InvertRect(mhDC, ref gr);
        }
Beispiel #8
0
        public void FillRect(GDIBrush brush, int x, int y, int width, int height)
        {
            RECTAPI gr;

            gr.Top    = y;
            gr.Left   = x;
            gr.Right  = width + x;
            gr.Bottom = height + y;

            NativeUser32Api.FillRect(mhDC, ref gr, brush.hBrush);
        }
Beispiel #9
0
        public void SetFont(Font font)
        {
            LogFont lf = new LogFont();

            font.ToLogFont(lf);
            lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;

            NativeUser32Api.SendMessage(
                hIMEWnd, (int)WindowMessage.WM_IME_CONTROL,
                IMC_SETCOMPOSITIONFONT,
                lf
                );
        }
Beispiel #10
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (Active)
     {
         if (e.Button != MouseButtons.None && (e.Button != MouseButtons.Middle && e.X != 0 && e.Y != 0))
         {
             Deactivate();
             Point p = new Point(e.X + this.Left, e.Y + this.Top);
             NativeUser32Api.SendMessage(this.Parent.Handle, WM_LBUTTONDOWN, 0, p.Y * 0x10000 + p.X);
         }
     }
 }
Beispiel #11
0
        private void RenderBorder()
        {
            IntPtr  hdc = NativeUser32Api.GetWindowDC(this.Handle);
            RECTAPI s   = new RECTAPI();

            NativeUser32Api.GetWindowRect(this.Handle, ref s);

            using (Graphics g = Graphics.FromHdc(hdc))
            {
                DrawingTools.DrawBorder((ControlBorderStyle)(int)this.BorderStyle, this.BorderColor, g, new Rectangle(0, 0, s.Width, s.Height));
            }
            NativeUser32Api.ReleaseDC(this.Handle, hdc);
        }
Beispiel #12
0
        public GDISurface(int width, int height, Control compatibleControl, bool bindControl)
        {
            IntPtr hDCControk = NativeUser32Api.ControlDC(compatibleControl);

            Init(width, height, hDCControk);
            NativeUser32Api.ReleaseDC(compatibleControl.Handle, hDCControk);

            if (bindControl)
            {
                Control = compatibleControl;
            }
            else
            {
            }

            Create();
        }
Beispiel #13
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();
        }
Beispiel #14
0
        public void Activate(int x, int y)
        {
            if (IsDirty)
            {
                CreateRegion();
            }

            this.Size              = new Size(Image.Width, Image.Height);
            this.Location          = new Point(x - Image.Width / 2, y - Image.Height / 2);
            this.ActivationPoint.X = x;
            this.ActivationPoint.Y = y;
            this.BringToFront();
            this.Visible = true;
            this.Focus();
            Active = false;
            Application.DoEvents();
            SetCursor(0, 0);
            tmrFeedback.Enabled = true;
            onBeginScroll(new EventArgs());
            NativeUser32Api.SendMessage(this.Handle, WM_MBUTTONDOWN, 0, 0);
            Active = true;
        }
Beispiel #15
0
        public void SetFont(string fontname, float fontsize)
        {
            LogFont tFont = new LogFont();

            tFont.lfItalic         = (byte)0;
            tFont.lfStrikeOut      = (byte)0;
            tFont.lfUnderline      = (byte)0;
            tFont.lfWeight         = 400;
            tFont.lfWidth          = 0;
            tFont.lfHeight         = (int)(-fontsize * 1.3333333333333);
            tFont.lfCharSet        = 1;
            tFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
            tFont.lfFaceName       = fontname;

            LogFont lf = tFont;

            NativeUser32Api.SendMessage(
                hIMEWnd, (int)WindowMessage.WM_IME_CONTROL,
                IMC_SETCOMPOSITIONFONT,
                lf
                );
        }
Beispiel #16
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (Active)
     {
         if (e.Button != MouseButtons.Middle && e.Button != MouseButtons.None)
         {
             Deactivate();
         }
         else
         {
             int x = e.X;
             int y = e.Y;
             x -= Image.Width / 2;
             y -= Image.Height / 2;
             SetCursor(x, y);
             NativeUser32Api.SendMessage(this.Handle, WM_MBUTTONDOWN, 0, 0);
         }
     }
     else
     {
         base.OnMouseMove(e);
     }
 }
Beispiel #17
0
        /// <summary>
        /// Start dragging the vertical splitter.
        /// </summary>
        public void InvokeMouseDownv()
        {
            IntPtr hwnd = Vertical.Handle;

            NativeUser32Api.SendMessage(hwnd, (int)WindowMessage.WM_LBUTTONDOWN, 0, 0);
        }
Beispiel #18
0
 public GDIPen(Color color, int width)
 {
     hPen = NativeGdi32Api.CreatePen(0, width, NativeUser32Api.ColorToInt(color));
     Create();
 }
Beispiel #19
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();
        }
Beispiel #20
0
 public GDIBrush(Color color)
 {
     hBrush = NativeGdi32Api.CreateSolidBrush(NativeUser32Api.ColorToInt(color));
     Create();
 }
Beispiel #21
0
 public GDIBrush(int Style, Color color)
 {
     hBrush = NativeGdi32Api.CreateHatchBrush(Style, NativeUser32Api.ColorToInt(color));
     Create();
 }
Beispiel #22
0
        public Size DrawTabbedString(string Text, int x, int y, int taborigin, int tabsize)
        {
            int ret = NativeUser32Api.TabbedTextOut(mhDC, x, y, Text, Text.Length, 1, ref tabsize, taborigin);

            return(new Size(ret & 0xFFFF, (ret >> 16) & 0xFFFF));
        }
Beispiel #23
0
        public Size MeasureTabbedString(string Text, int tabsize)
        {
            uint ret = NativeUser32Api.GetTabbedTextExtent(mhDC, Text, Text.Length, 1, ref tabsize);

            return(new Size((int)(ret & 0xFFFF), (int)((ret >> 16) & 0xFFFF)));
        }