“熊猫视图”.Net图形控件功能介绍 [二]:一行代码实现图形图像缩放平操作

发布于:2022-12-20 ⋅ 阅读:(604) ⋅ 点赞:(0)

“熊猫视图”.Net图形控件功能介绍 [三]:前景层与背景层


        在 .Net 项目中,引用并拖拽“熊猫视图”控件到窗体后,在Form窗体“Shown”事件中编写一行代码即可实现对视图中图形图像的缩小、放大、平移操作。

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            pandaView1.FullView();
        }
    }
}

此时视图处于全图显示状态并支持缩放平操作。但在没有图形图像内容时做缩放平操作是看不到任何效果的,因此需要绘制图形。

        “熊猫视图”控件中内置了若干类型的基本图元。这里暂以一百个随机颜色、随机位置的透明矩形为例,完整代码如下:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Random r = new Random();
            for (int i = 0; i < 100; i++)
            {
                PandaView.Rectangle rec = new PandaView.Rectangle();
                PointF p1 = new PointF(r.Next(0, 1000), r.Next(0, 1000));
                PointF p2 = new PointF(p1.X + r.Next(50, 100), p1.Y + r.Next(50, 100));
                rec.Points = new[] { p1, p2 };
                rec.Pen = new Pen(Color.FromArgb(r.Next(50, 255), r.Next(50, 255), r.Next(50, 255)),1);
                rec.Fill = true;
                rec.FillBrush = new SolidBrush(Color.FromArgb(r.Next(80, 255), r.Next(50, 255), r.Next(50, 255), r.Next(50, 255)));
                rec.Creat(pandaView1);
            }
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            pandaView1.FullView();
        }
    }
}

使用鼠标滚轮缩放,运行效果如下:

也支持使用语句缩小放大。