using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Drawing;namespace PtechClassLibrary{ public class Class1 { public void DrawPic(MouseEventArgs e,int flag,PictureBox petchPic) { Point myPT = new Point(e.X, e.Y);//获取鼠标单击位置 PictureBox pbox = new PictureBox();//实例化PictureBox控件 pbox.Location = myPT;//指定PictureBox控件的位置 pbox.BackColor = Color.Transparent;//设置PictureBox控件的背景色 pbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;//设置PictureBox控件的图片显示方式 switch (flag)//判断标识 { case 0: pbox.Size = new System.Drawing.Size(20, 18);//设置PictureBox控件大小 pbox.Image = Image.FromFile("2.gif");//设置PictureBox控件要显示的图像 break; case 1: pbox.Size = new System.Drawing.Size(30, 31);//设置PictureBox控件大小 pbox.Image = Image.FromFile("3.gif");//设置PictureBox控件要显示的图像 break; case 2: pbox.Size = new System.Drawing.Size(34, 30);//设置PictureBox控件大小 pbox.Image = Image.FromFile("1.gif");//设置PictureBox控件要显示的图像 break; } if (e.Button == MouseButtons.Left)//判断是否单击了鼠标左键 { petchPic.Controls.Add(pbox);//将PictureBox控件添加到树枝上 } } }}
评论