c#做连连看如何将多个图片添加到form上
2个回答
展开全部
你的图片可以放到一个目录 里,然后动态读取就行了!
给你看个案例:
private void FormMenuIcon_Load(object sender, EventArgs e)
{
string sFilePath = Application.StartupPath + "\\images\\menu_icon";
DirectoryInfo dInfo = new DirectoryInfo(sFilePath);
int nWidth = 3;
int nHeight = 3;
PictureBox pBox = null;
FileInfo[] fInfoList = dInfo.GetFiles();
for (int i = 0; i < fInfoList.Length; i++)
{
FileInfo fInfo = fInfoList[i];
if (fInfo.Extension.ToLower() == ".gif" || fInfo.Extension.ToLower() == ".jpg")
{
string sImageUrl = sFilePath + "\\" + fInfo.Name;
pBox = new PictureBox();
pBox.ImageLocation = sImageUrl;
pBox.SizeMode = PictureBoxSizeMode.AutoSize;
pBox.Location = new System.Drawing.Point(nWidth, nHeight);
pBox.Cursor = Cursors.Hand;
pBox.Click += new EventHandler(pBox_Click);
pBox.Name = fInfo.Name;
nWidth = pBox.Location.X + 25 + 3;
if ((nWidth) > panelImage.Width)
{
nHeight = pBox.Location.Y + 22 + 3;
nWidth = 3;
}
panelImage.Controls.Add(pBox);
}
}
}
/// <summary>
/// 为菜单定义委托
/// </summary>
/// <param name="oSender">源对象</param>
public delegate void ImageOnClick(object oSender );
/// <summary>
/// 为菜单定义委托
/// </summary>
public ImageOnClick ImageOnClickBack = null;
/// <summary>
/// 图片单击事件
/// </summary>
void pBox_Click(object sender, EventArgs e)
{
if (ImageOnClickBack != null)
{
ImageOnClickBack.Invoke(sender);
}
else
{
//throw new Exception("ImageOnClickBack 未初始化!");
}
_instance = null;
this.Dispose();
}
改成连连看,你就得先将那几个图片成对读到一个数组里,再随机生成位置就OK啦!
给你看个案例:
private void FormMenuIcon_Load(object sender, EventArgs e)
{
string sFilePath = Application.StartupPath + "\\images\\menu_icon";
DirectoryInfo dInfo = new DirectoryInfo(sFilePath);
int nWidth = 3;
int nHeight = 3;
PictureBox pBox = null;
FileInfo[] fInfoList = dInfo.GetFiles();
for (int i = 0; i < fInfoList.Length; i++)
{
FileInfo fInfo = fInfoList[i];
if (fInfo.Extension.ToLower() == ".gif" || fInfo.Extension.ToLower() == ".jpg")
{
string sImageUrl = sFilePath + "\\" + fInfo.Name;
pBox = new PictureBox();
pBox.ImageLocation = sImageUrl;
pBox.SizeMode = PictureBoxSizeMode.AutoSize;
pBox.Location = new System.Drawing.Point(nWidth, nHeight);
pBox.Cursor = Cursors.Hand;
pBox.Click += new EventHandler(pBox_Click);
pBox.Name = fInfo.Name;
nWidth = pBox.Location.X + 25 + 3;
if ((nWidth) > panelImage.Width)
{
nHeight = pBox.Location.Y + 22 + 3;
nWidth = 3;
}
panelImage.Controls.Add(pBox);
}
}
}
/// <summary>
/// 为菜单定义委托
/// </summary>
/// <param name="oSender">源对象</param>
public delegate void ImageOnClick(object oSender );
/// <summary>
/// 为菜单定义委托
/// </summary>
public ImageOnClick ImageOnClickBack = null;
/// <summary>
/// 图片单击事件
/// </summary>
void pBox_Click(object sender, EventArgs e)
{
if (ImageOnClickBack != null)
{
ImageOnClickBack.Invoke(sender);
}
else
{
//throw new Exception("ImageOnClickBack 未初始化!");
}
_instance = null;
this.Dispose();
}
改成连连看,你就得先将那几个图片成对读到一个数组里,再随机生成位置就OK啦!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询