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. sizeof()用法汇总

    sizeof()功能:计算数据空间的字节数 1.与strlen()比较      strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素.      ...

  2. Oracle数据库入门——如何根据物化视图日志快速刷新物化视图

    Oracle物化视图的快速刷新机制是通过物化视图日志完成的.Oracle如何通过一个物化视图日志就可以支持多个物化视图的快速刷新呢,本文简单的描述一下刷新的原理. 首先,看一下物化视图的结构:SQL& ...

  3. Android ListView OnItemLongClick和OnItemClick事件内部细节分享以及几个比较特别的属性

    本文转自 http://blog.sina.com.cn/s/blog_783ede030101bnm4.html 作者kiven 辞职3,4个月在家休息,本以为楼主要程序员逆袭,结果失败告终继续码农 ...

  4. js判定IE

    var ie=!-[1,]; 这句话对于多数前端来说都很熟悉,遇到判定是否是ie浏览器就用这个,但是对于由来以及为什么可能没有深入了解过. 短短6个bytes就做了判定.这个表达式是利用IE和标准浏览 ...

  5. 新浪微博OAuth2.0的用法

    最近学习Android开发,照着视频开发新浪微博,但是视频里的介绍的是OAuth1.0的授权方式,试了半天发现用不了. 原来现在一般没审核的用户只能使用OAuth2.0了,视频教学里的方法已经过时了. ...

  6. NSNotification Name 最佳写法

    本文主要借探讨NSNotificationName的最佳写法的机会,学习下extern, static, const, #define 和常量指针与指针常量等的特性和用法. 1.NSNotificat ...

  7. Tips11:用[Rang]来限制Inspector中的变量

    我们在写脚本的过程中可能会用到很多Public变量,如INT型,Float型,这些变量在项目中可能有着一个默认的实际范围,如血量不能为负数,而且int float本来就是有一个范围的,如果对这些变量加 ...

  8. Direct3D11学习:(九)绘制基本几何体

    转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 Direct3D中很多复杂的几何效果都是由基本的几何体组合而成的,这篇文章中,我们来学习集中常见的基本几何体的绘 ...

  9. JAVA jdbc(数据库连接池)学习笔记(二) SQL注入

    PS:今天偶然间发现了SQL的注入...所以就简单的脑补了一下,都是一些简单的例子...这篇写的不怎么样...由于自己没有进行很深的研究... 学习内容: 1.SQL注入的概念...   所谓SQL注 ...

  10. 2013/11/22工作随笔-缓存是放在Model层还是放在Controller层

    web网站的典型代码框架就是MVC架构,Model层负责数据获取,Controller层负责逻辑控制,View层则负责展示. 一般数据获取是去mysql中获取数据 但是这里有个问题,我们不会每次请求都 ...