private void setSource(bool newmag)
    {
        if (!this.IsHandleCreated || this.DesignMode)
        {
            return;
        }
        if (newmag)
        {
            var xform = new MAGTRANSFORM();
            xform.v11 = xform.v22 = magnification;
            xform.v33 = 1.0f;
            MagSetWindowTransform(this.Handle, ref xform);
        }
        Point center;

        if (trackMouse)
        {
            center = Cursor.Position;
        }
        else
        {
            var rc = this.RectangleToScreen(this.Bounds);
            center = new Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);
        }
        var scr  = Screen.FromPoint(center);
        var rect = new RECT();

        rect.left  = Math.Max(scr.Bounds.Left, center.X - (int)(this.Width / magnification / 2));
        rect.top   = Math.Max(scr.Bounds.Top, center.Y - (int)(this.Height / magnification / 2));
        rect.right = rect.left + (int)(this.Width / magnification);
        if (rect.right > scr.Bounds.Right)
        {
            rect.right = scr.Bounds.Right;
            rect.left  = rect.right - (int)(this.Width / magnification);
        }
        rect.bottom = center.Y + (int)(this.Height / magnification);
        if (rect.bottom > scr.Bounds.Bottom)
        {
            rect.bottom = scr.Bounds.Bottom;
            rect.top    = rect.bottom - (int)(this.Height / magnification);
        }
        MagSetWindowSource(this.Handle, ref rect);
        this.Invalidate();
    }
예제 #2
0
 internal static extern bool MagSetWindowTransform(IntPtr hwnd, ref MAGTRANSFORM pTransform);
 private static extern bool MagSetWindowTransform(IntPtr hWnd, ref MAGTRANSFORM xform);