14年6月 好友结婚

14年4月左右知道他们婚礼由迎宾照抽奖的环节

问我有没有可以用的抽奖软件

我网上找了一会儿,就放弃了,自己做一个更快不是?

14年6月,PC宴会图片抽奖软件成功使用

---

操作示意图:

图片文字模式2选1

1.文字模式只需要指定txt文本文件路劲

会按序滚动txt文本文件内容进行抽奖

2.图片模式需要设定

清晰图片文件夹

缩略图文件夹

缩略倍数

后,生成缩略图即可

---

部分代码:

main.cs

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading; namespace partyGifts
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
} private void Main_Load(object sender, EventArgs e)
{
this.cbType.SelectedIndex = ;
} private void cbType_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.cbType.SelectedItem.ToString().Equals("图片"))
{
this.btnSource.Text = "图片文件夹(不含子目录)";
parms.type = "图片";
parms.path = "";
}
else if (this.cbType.SelectedItem.ToString().Equals("文字"))
{
this.btnSource.Text = "文字文件(*.txt)";
parms.type = "文字";
parms.path = "";
}
} private void btnSource_Click(object sender, EventArgs e)
{
if (this.cbType.SelectedItem.ToString().Equals("图片"))
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.lblSource.Text = fbd.SelectedPath;
parms.path = fbd.SelectedPath;
}
}
else if (this.cbType.SelectedItem.ToString().Equals("文字"))
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件(*.txt)|*.txt";
ofd.Multiselect = false;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.lblSource.Text = ofd.FileName;
parms.path = ofd.FileName;
}
}
} private void btnBgColor_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.FullOpen = true;
if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.btnBgColor.BackColor = cd.Color;
parms.bgColor = cd.Color;
}
} private void btnFontColor_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.FullOpen = true;
if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.btnFontColor.BackColor = cd.Color;
parms.fontColor = cd.Color;
}
} private void numTime_ValueChanged(object sender, EventArgs e)
{
parms.timeNum = (int)this.numTime.Value;
} private void btnStart_Click(object sender, EventArgs e)
{
if (!parms.path.Equals(""))
{
gifts g = new gifts();
g.Show();
}
else
{
MessageBox.Show("请选择数据来源!");
}
} private void txtFTxt_TextChanged(object sender, EventArgs e)
{
parms.firstTxt = this.txtFTxt.Text;
} private void btnFPic_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "图片文件(*.jpg,*.jpeg,*.gif,*.bmp,*.png)|*.jpg;*.jpeg;*.gif;*.bmp;*.png";
ofd.Multiselect = false;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.lblFPic.Text = ofd.FileName;
parms.firstPicUrl = ofd.FileName;
}
else
{
this.lblFPic.Text = "";
parms.firstPicUrl = "";
}
} private void cb1_CheckedChanged(object sender, EventArgs e)
{
parms.cb1 = this.cb1.Checked;
} private void btnSlPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.lblSl.Text = fbd.SelectedPath;
parms.thumbPath = fbd.SelectedPath;
}
else
{
this.lblSl.Text = "";
parms.thumbPath = "";
}
} private void btnDoSl_Click(object sender, EventArgs e)
{
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
DialogResult dr = MessageBox.Show("该处理会删除缩略图文件夹后重新生成文件夹\n是否继续?", "提示信息", messButton);
if (dr == DialogResult.OK)
{
if (new DirectoryInfo(parms.thumbPath).Exists)
{
foreach (FileInfo item in new DirectoryInfo(parms.thumbPath).GetFiles())
{
item.Delete();
}
} if (parms.path != "" && parms.type == "图片")
{
DirectoryInfo di = new DirectoryInfo(parms.path);
FileInfo[] fiLst = di.GetFiles();
foreach (FileInfo fi in fiLst)
{
parms.MakeThumbnail(fi.FullName, parms.thumbPath + "\\" + fi.Name, System.Windows.Forms.SystemInformation.VirtualScreen.Width / (int)numBS.Value, System.Windows.Forms.SystemInformation.VirtualScreen.Height / (int)numBS.Value, "W");
}
MessageBox.Show("缩略图生成完成,请继续操作");
}
else
{
MessageBox.Show("请选择图片模式,且填写完图片文件夹路径");
}
}
}
}
}

gifts.cs

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices; namespace partyGifts
{
public partial class gifts : Form
{ [DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]
public extern static void ShowCursor(int status); public gifts()
{
InitializeComponent();
} private Timer timer = new Timer(); private void gifts_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Escape:
timer.Stop();
parms.txtList.Clear();
this.Close();
return;
case Keys.Space:
parms.playSts = !parms.playSts;
if (!parms.playSts)
{
if (parms.type.Equals("图片") && parms.cb1)
{
timer.Stop();
this.lblFont.Visible = false;
this.picBox.ImageLocation = parms.txtList[selectIndex];
this.picBox.Refresh();
}
else if (parms.type.Equals("图片") && parms.thumbPath != "")
{
this.picBox.ImageLocation = parms.path + "\\" + this.imgNameAllLst[selectIndex];
}
}
else {
if (parms.type.Equals("图片") && parms.cb1)
{
timer.Stop();
this.lblFont.Visible = false;
}
}
break;
default: break;
}
goOn();
} private void goOn()
{
if (parms.playSts)
{
//getOut
if (- != selectIndex)
{
parms.txtList.RemoveAt(selectIndex);
if (parms.type.Equals("图片"))
{
imgNameLst.RemoveAt(selectIndex);
imgNameAllLst.RemoveAt(selectIndex);
}
if ( == parms.txtList.Count)
{
timer.Stop();
parms.txtList.Clear();
MessageBox.Show("全部中奖,抽奖结束");
this.Close();
return;
}
if ( != selectIndex)
{
selectIndex--;
}
else
{
selectIndex = parms.txtList.Count;
}
}
else
{
if (parms.type.Equals("图片"))
this.picBox.Visible = true;
if (parms.type.Equals("图片") && parms.cb1)
{
this.picBox.Controls.Add(this.lblFont);
}
}
timer.Start();
}
else
{
timer.Stop();
}
}
private Label lblFont = new Label();
private void gifts_Load(object sender, EventArgs e)
{
timer.Interval = parms.timeNum;
timer.Tick += timer_Tick;
lblFont.ForeColor = parms.fontColor;
this.BackColor = parms.bgColor;
lblFont.Font = new Font(lblFont.Font, FontStyle.Bold);
lblFont.Font = new Font(this.Font.FontFamily, );
lblFont.BackColor = Color.Transparent;
lblFont.Size = new Size(this.Width, this.Height);
lblFont.Top = ;
lblFont.Left = ;
lblFont.Text = parms.firstTxt;
lblFont.TextAlign = ContentAlignment.MiddleCenter; this.picBox.Left = ;
this.picBox.Top = ;
this.picBox.Size = new Size(this.Width, this.Height); if (!parms.firstPicUrl.Equals(string.Empty))
{
//lblFont.Image = new Bitmap(parms.firstPicUrl);
//this.lblFont.Visible = false;
this.picBox.Visible = true;
this.picBox.ImageLocation = parms.firstPicUrl;
this.picBox.Controls.Add(lblFont);
}
else
{
this.picBox.Visible = false;
this.Controls.Add(lblFont);
}
if (parms.type.Equals("文字"))
{
StreamReader sr = new StreamReader(new FileStream(parms.path, FileMode.Open), Encoding.UTF8);
string lstTmp = sr.ReadLine();
while (lstTmp != null)
{
parms.txtList.Add(lstTmp);
lstTmp = sr.ReadLine();
}
}
else
{
DirectoryInfo di;
if (parms.thumbPath != "")
{
di = new DirectoryInfo(parms.thumbPath);
}
else
{
di = new DirectoryInfo(parms.path);
}
FileInfo[] fiLst = di.GetFiles();
foreach (FileInfo fi in fiLst)
{
parms.txtList.Add(fi.FullName);
imgNameLst.Add(fi.Name.Replace(fi.Extension, ""));
imgNameAllLst.Add(fi.Name);
}
//if (parms.firstPicUrl.Equals(string.Empty) && !parms.cb1)
//this.picBox.InitialImage = new Bitmap(parms.txtList[0]);
}
ShowCursor();
}
private List<string> imgNameLst = new List<string>();
private List<string> imgNameAllLst = new List<string>();
private int selectIndex = -;
void timer_Tick(object sender, EventArgs e)
{
selectIndex = ++selectIndex % parms.txtList.Count;
if (parms.type.Equals("文字"))
{
this.lblFont.Text = parms.txtList[selectIndex];
}
else
{
this.lblFont.Visible = false;
if (!parms.cb1)
{
this.picBox.ImageLocation = parms.txtList[selectIndex];
}
else
{
this.picBox.Image = null;
this.lblFont.Visible = true;
this.lblFont.Text = this.imgNameLst[selectIndex];
}
//this.picBox.Image = imgLst[selectIndex];
}
} private void gifts_FormClosing(object sender, FormClosingEventArgs e)
{
parms.playSts = false;
//this.picBox.InitialImage.Dispose();
this.picBox.Dispose();
ShowCursor();
} }
}

parms.cs

 using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text; namespace partyGifts
{
public class parms
{
public static string path = "";
public static string type = "";
public static int timeNum = ;
public static Color bgColor;
public static Color fontColor;
public static List<string> txtList = new List<string>();
public static bool playSts = false;
public static string firstTxt = "尽请期待";
public static string firstPicUrl = string.Empty;
public static bool cb1 = false;
public static string thumbPath = ""; /**/
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="originalImagePath">源图路径(物理路径)</param>
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">生成缩略图的方式</param>
public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
Image originalImage = Image.FromFile(originalImagePath); int towidth = width;
int toheight = height; int x = ;
int y = ;
int ow = originalImage.Width;
int oh = originalImage.Height; switch (mode)
{
case "HW"://指定高宽缩放(可能变形)
break;
case "W"://指定宽,高按比例
toheight = originalImage.Height * width / originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height / originalImage.Height;
break;
case "Cut"://指定高宽裁减(不变形)
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
{
oh = originalImage.Height;
ow = originalImage.Height * towidth / toheight;
y = ;
x = (originalImage.Width - ow) / ;
}
else
{
ow = originalImage.Width;
oh = originalImage.Width * height / towidth;
x = ;
y = (originalImage.Height - oh) / ;
}
break;
default:
break;
} //新建一个bmp图片
Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板
Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充
g.Clear(Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, new Rectangle(, , towidth, toheight),
new Rectangle(x, y, ow, oh),
GraphicsUnit.Pixel); try
{
//以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
} }
}

---

CSDN代码及程序下载:

http://download.csdn.net/detail/wangxsh42/8391929

使用者:下载后,可以直接使用:

partyGifts\bin\Debug\partyGifts.exe

最新文章

  1. 一个android参考网站,工具+源码
  2. Adobe Dreamweaver代码编辑
  3. motto7
  4. Compare Version Number
  5. [EXCEL] 在单元格中自动输入时间和日期
  6. BigDecimal类对象的使用详解
  7. [LeetCode]题解(python):143-Reorder List
  8. 多线程——@synchronized(object)
  9. 201521123107 《Java程序设计》第11周学习总结
  10. 笔记:创建Jersey REST 服务,基于Maven
  11. Spark MLlib数据类型
  12. HTML中的javascript交互
  13. struts2-第一章-基础用法3
  14. ERROR: invalid byte sequence for encoding &quot;UTF8&quot;: 0x00
  15. AIROBOT系统 之 私人存储 和 DLNA 智能电视云
  16. PHP匿名函数
  17. YYModel HandyJson
  18. VSCode and NoteBook for JavaScript | NodeJS
  19. git如何拉取指定分支的代码
  20. 使用C#读取网站相对路径文件夹下所有图片

热门文章

  1. Mac终端常用命令收集
  2. UNIX环境高级编程笔记之进程环境
  3. Eclipse中用Logcat调试程序
  4. Java程序性能优化Tip
  5. 关于python协程的一个例子的学习
  6. 深入理解图优化与g2o:图优化篇
  7. 十一、EnterpriseFrameWork框架的分层与系统业务的结合
  8. MyBatis知多少(13)MyBatis如何解决数据库的常见问题
  9. 2014 网选 广州赛区 hdu 5025 Saving Tang Monk(bfs+四维数组记录状态)
  10. python异常处理(基础)