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

[原创]winform_PC宴会图片抽奖/文字抽奖的更多相关文章

  1. c# ToolStrip控件图片和文字显示--原创

    如上图达到这样的效果 首先我们给属性Image和Text分别赋予需要显示的图片和文字 然后设置DisplyStyle属性为ImageAndText,意为同时显示图片和文字 各种设置ImageAlign ...

  2. 自定义带图片和文字的ImageTextButton

    今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...

  3. WPF_界面_图片/界面/文字模糊解决之道整理

    原文:WPF_界面_图片/界面/文字模糊解决之道整理 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010265681/article/detai ...

  4. DIV+CSS 让同一行的图片和文字对齐【转藏】

    DIV+CSS 让同一行的图片和文字对齐 DIV+CSS 让同一行的图片和文字对齐 在div+css布局中,如果一行(或一个DIV)内容中有图片和文字的话,图片和文字往往会一个在上一个在下,这是一个新 ...

  5. 鼠标滑过图片变暗文字链接滑出jQuery特效

    效果体验:http://hovertree.com/texiao/jquery/7.htm HTML文件代码: <!DOCTYPE html> <html xmlns="h ...

  6. ios图片添加文字或者水印

    在项目中,我们会对图片做一些处理,但是我们要记住,一般在客户端做图片处理的数量不宜太多,因为受设备性能的限制,如果批量的处理图片,将会带来交互体验性上的一些问题.首先让我们来看看在图片上添加文字的方法 ...

  7. iOS开发小技巧--即时通讯项目:使用富文本在UILabel中显示图片和文字;使用富文本占位显示图片

    Label借助富文本显示图片 1.即时通讯项目中语音消息UI的实现,样式如图: 借助富文本在UILabel中显示图片和文字 // 1.创建一个可变的富文本 NSMutableAttributedStr ...

  8. php 图片添加文字水印 以及 图片合成(微信快码传播)

    1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...

  9. ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案

    原文:ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案 根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页 ...

随机推荐

  1. 算法导论第十八章 B树

    一.高级数据结构 本章以后到第21章(并查集)隶属于高级数据结构的内容.前面还留了两章:贪心算法和摊还分析,打算后面再来补充.之前的章节讨论的支持动态数据集上的操作,如查找.插入.删除等都是基于简单的 ...

  2. 尝鲜CodeBlocks

    在寻找跨平台的C++ IDE,就尝试了CodeBlocks,写了个HelloWorld,测试了一下C++11的代码,我很喜欢他的代码着色,看着很清爽. 记得要打开C++11的支持:

  3. Java NIO原理分析

    Java IO 在Client/Server模型中,Server往往需要同时处理大量来自Client的访问请求,因此Server端需采用支持高并发访问的架构.一种简单而又直接的解决方案是“one-th ...

  4. 关于app.config不能即时保存读取的解决方案

    public void saveValue(string Name, string Value) { ConfigurationManager.AppSettings.Set(Name, Value) ...

  5. 在Java中直接调用js代码(转载)

    http://blog.csdn.net/xzyxuanyuan/article/details/8062887 JDK1.6版添加了新的ScriptEngine类,允许用户直接执行js代码. 在Ja ...

  6. 二十二、【轻量级开源框架】EFW框架Web前端开发之JqueryEasyUI

    回<[开源]EFW框架系列文章索引>        EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan ...

  7. android判断EditText输入的数字、中文还是字母方法

    String txt = edInput.getText().toString(); Pattern p = Pattern.compile("[0-9]*");      Mat ...

  8. ruby中Hash排序

    当values都是整形时,按照Hash的Values排序: h = {'a'=>1,'b'=>2,'c'=>5,'d'=>4} h.sort {|a,b| a[1]<=& ...

  9. How ADB works

    ADB (Android Debug Bridge): How it works? 2012.2.6 early draft Tetsuyuki Kobayashi What is ADB? If y ...

  10. js转html实体

    方法一: 用的浏览器内部转换器实现转换,方法是动态创建一个容器标签元素,如DIV,将要转换的字符串设置为这个元素的innerText,然后返回这个元素的innerHTML,即得到经过HTML编码转换的 ...