首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#中水晶表格能实现让用户随意拖动改变报表的大小,来适应打印纸张么

2012-08-14 
C#中水晶报表能实现让用户随意拖动改变报表的大小,来适应打印纸张么设计出来的水晶报表要实现能让用户自动

C#中水晶报表能实现让用户随意拖动改变报表的大小,来适应打印纸张么
设计出来的水晶报表要实现能让用户自动拖放,改变报表的 大小

[解决办法]

C# code
#region 定义全局变量        //定义全局变量width,用来存放当前活动窗体的width        static int width = 0;        static int height = 0;        static int count = 0;        //分别声明四条虚线的起点与终点        static Point p1 = new Point(0, 10);        static Point p2;        static Point p3;        static Point p4;        static Point p5 = new Point(10, 0);        static Point p6;        static Point p7;        static Point p8;        //是否选中        static bool isClick = false;        //设置字体颜色        Font font = new Font("宋体", 8);        #endregion        public Frm_Report()        {            InitializeComponent();        }        private void Frm_Report_Load(object sender, EventArgs e)        {            //避免闪烁,使用辅助缓冲区            this.DoubleBuffered = true;            //设置窗体最大化            this.WindowState = FormWindowState.Maximized;            //实例化一个用户选择的打印机            PrintDialog _Dialog = new PrintDialog();            width = _Dialog.PrinterSettings.DefaultPageSettings.PaperSize.Width;       //827            height = _Dialog.PrinterSettings.DefaultPageSettings.PaperSize.Height;     //1169            p2 = new Point(width, 10);            p3 = new Point(0, height - 100);            p4 = new Point(width, height - 100);            p6 = new Point(10, height);            p7 = new Point(width - 10, 0);            p8 = new Point(width - 10, height);        }        /// <summary>        /// 鼠标左键按下        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Frm_Report_MouseDown(object sender, MouseEventArgs e)        {            //判断用户按下时,鼠标所在的区域在不在四条虚线上            if ((e.X - p1.X >= 0) && (e.X - p2.X <= 0))            {                if (e.Y <= p1.Y + 5 && e.Y >= p1.Y - 5)                {                    isClick = true;                    count = 1;                    Cursor.Current = Cursors.SizeNS;                }                if (e.Y <= p3.Y + 5 && e.Y >= p3.Y - 5)                {                    isClick = true;                    count = 2;                    Cursor.Current = Cursors.SizeNS;                }            }            if ((e.Y - p5.Y >= 0) && (e.Y - p6.Y <= 0))            {                if (e.X <= p5.X + 5 && e.X >= p5.X - 5)                {                    isClick = true;                    count = 3;                    Cursor.Current = Cursors.SizeWE;                }                if (e.X <= p7.X + 5 && e.X >= p7.X - 5)                {                    isClick = true;                    count = 4;                    Cursor.Current = Cursors.SizeWE;                }            }        }        /// <summary>        /// 鼠标左键按下且在按下的状态下拖动        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Frm_Report_MouseMove(object sender, MouseEventArgs e)        {            this.Invalidate();        }        /// <summary>        /// 鼠标左键松开        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Frm_Report_MouseUp(object sender, MouseEventArgs e)        {            if (isClick)            {                //判断选中的是那条直线                if (count == 1)                {                    if (e.Y >= 10 && e.Y <= height / 2 - 40)                    {                        p1.Y = e.Y;                        p2.Y = e.Y;                    }                    else if (e.Y < 10)                    {                        p1.Y = 10;                        p2.Y = 10;                    }                    else                    {                        p1.Y = height / 2 - 40;                        p2.Y = height / 2 - 40;                    }                    //修改选中状态                    isClick = false;                    //重绘                    this.Refresh();                }                if (count == 2)                {                    if (e.Y <= height - 10 && e.Y >= height / 2 + 40)                    {                        p3.Y = e.Y;                        p4.Y = e.Y;                    }                    else if (e.Y > height - 10)                    {                        p3.Y = height - 10;                        p4.Y = height - 10;                    }                    else                    {                        p3.Y = height / 2 + 40;                        p4.Y = height / 2 + 40;                    }                    isClick = false;                    this.Refresh();                }                if (count == 3)                {                    if (e.X >= 10 && e.X <= width / 2 - 40)                    {                        p5.X = e.X;                        p6.X = e.X;                    }                    else if (e.X < 10)                    {                        p5.X = 10;                        p6.X = 10;                    }                    else                    {                        p5.X = width / 2 - 40;                        p6.X = width / 2 - 40;                    }                    isClick = false;                    this.Refresh();                }                if (count == 4)                {                    if (e.X <= width - 10 && e.X >= width / 2 + 40)                    {                        p7.X = e.X;                        p8.X = e.X;                    }                    else if (e.X > width - 10)                    {                        p7.X = width - 10;                        p8.X = width - 10;                    }                    else                    {                        p7.X = width / 2 + 40;                        p8.X = width / 2 + 40;                    }                    isClick = false;                    this.Refresh();                }            }        } 

热点排行