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. 关于bootstrapValidator提交问题的解决

    关于bootstrapValidator的AJAX提交有几种方法: 1.form中一定要放一个类型为submit的按钮,然后添加 success.form.bv 事件,如下 on('success.f ...

  2. 原生js提交表单

    /********************* 表单提交 ***********************/ function ajax(options) { options = options || { ...

  3. EditorWindow中手动控制焦点

    在Unity3D中制作编辑器的时候,有时候会需要手动控制界面上控件的焦点,与此相关的有三个函数都在下面的示例代码中了: public void Test() { // 给控件命名 GUI.SetNex ...

  4. 如何用参数化SQL语句污染你的计划缓存

    你的SQL语句的参数化总是个好想法.使用参数化SQL语句你不会污染你的计划缓存——错!!!在这篇文章里我想向你展示下用参数化SQL语句就可以污染你的计划缓存,这是非常简单的! ADO.NET-AddW ...

  5. nginx的部署与发布

    1.在http://nginx.org/en/download.html下载nginx.tar.gz包. 2.上传发送到服务器(wcp工具) 3.用tar -xf命令解压gz包 4.[配置安装变量]: ...

  6. 关于SQL SERVER高并发解决方案

    现在大家都比较关心的问题就是在多用户高并发的情况下,如何开发系统,这对我们程序员来说,确实是值得研究,最近找工作面试时也经常被问到,其实我早有去关心和了解这类问题,但一直没有总结一下,导致面试时无法很 ...

  7. 深度使用react-native的热更新能力,必须知道的一个shell命令

    开篇之前,先讲一个自己开发中的一个小插曲: 今天周日,iOS版 App 周一提交,周三审核通过上架,很给力.不过,中午11:30的时候,运营就反应某个页面有一个很明显的问题,页面没法拉到底部,部分信息 ...

  8. [JS] jQuery选择器

    jQuery 选择器 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id=lastname 的元素 .class $(& ...

  9. nodejs+express+jade+mongodb给我baby做个小相册(2)-留言板

    上一篇简单的实现了下照片的展现跟浏览功能,这一篇我将给这个程序添加一个留言的功能.那么留言的话肯定要涉及到数据持久了,其实对于这个小功能的话,用个xml就可以,不过为了看起来更加高大上,我决定使用mo ...

  10. 【原创随笔】Sql2008 R2 做CQRS小结

    1.做数据同步,订阅服务器只要把数据库建好就可以了,至于表和存储过程以及其它的都不管,订阅的时候会自动创建这些信息. 2.选择事务发布(如果同步表,表至少要带主键,不然不能选择) 3.在发布的时候,用 ...