[原创]winform_PC宴会图片抽奖/文字抽奖
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宴会图片抽奖/文字抽奖的更多相关文章
- c# ToolStrip控件图片和文字显示--原创
如上图达到这样的效果 首先我们给属性Image和Text分别赋予需要显示的图片和文字 然后设置DisplyStyle属性为ImageAndText,意为同时显示图片和文字 各种设置ImageAlign ...
- 自定义带图片和文字的ImageTextButton
今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...
- WPF_界面_图片/界面/文字模糊解决之道整理
原文:WPF_界面_图片/界面/文字模糊解决之道整理 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010265681/article/detai ...
- DIV+CSS 让同一行的图片和文字对齐【转藏】
DIV+CSS 让同一行的图片和文字对齐 DIV+CSS 让同一行的图片和文字对齐 在div+css布局中,如果一行(或一个DIV)内容中有图片和文字的话,图片和文字往往会一个在上一个在下,这是一个新 ...
- 鼠标滑过图片变暗文字链接滑出jQuery特效
效果体验:http://hovertree.com/texiao/jquery/7.htm HTML文件代码: <!DOCTYPE html> <html xmlns="h ...
- ios图片添加文字或者水印
在项目中,我们会对图片做一些处理,但是我们要记住,一般在客户端做图片处理的数量不宜太多,因为受设备性能的限制,如果批量的处理图片,将会带来交互体验性上的一些问题.首先让我们来看看在图片上添加文字的方法 ...
- iOS开发小技巧--即时通讯项目:使用富文本在UILabel中显示图片和文字;使用富文本占位显示图片
Label借助富文本显示图片 1.即时通讯项目中语音消息UI的实现,样式如图: 借助富文本在UILabel中显示图片和文字 // 1.创建一个可变的富文本 NSMutableAttributedStr ...
- php 图片添加文字水印 以及 图片合成(微信快码传播)
1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...
- ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案
原文:ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案 根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页 ...
随机推荐
- 关于Linux session管理与GUI架构
google了一下感觉一下子找不到太好的资料,可能需要慢慢深入去学习. 这里有一个讲session management的,还算比较深入: https://dvdhrm.wordpress.com/2 ...
- CSS之边框覆盖
今天想做一个淘宝导航来练练手,遇到了边框覆盖的问题.如下图: li的红色边框盖不住该灰色边框.后来问经验人士告诉我,这种边框覆盖是会出现无法100%保证正常的情况,遂得到如下3中解决方案: 1.以后遇 ...
- [原]Android打包之Gradle打包
最近尝试了一下Android的Gradle打包,发现确实比Ant打包会方便很多,特此记录下来. 注:android的gradle现在插件的版本已经是0.14.3了,对于一些老的方法和api,有一些已经 ...
- 20个精美的免费 PSD 界面设计素材【免费下载】
在这篇文章中,我们给大家收集了20个最新出炉的 UI 设计素材.这些来自优秀设计师的 PSD 源文件素材让其它的设计师们在设计用户界面原型的时候能够非常便利.些界面素材让他们使用快速和有效的方式完成用 ...
- iOS-UITableView-处理cell上按钮事件(弹出警示框,页面跳转等)
一. 目的: 实现UITableViewCell上按钮点击事件可以进行页面跳转. 二. 实现方法: 1. 用协议的方式的实现. 2. 需要自定义UITableViewCell. 三. 代码部分. ce ...
- [Architect] Abp 框架原理解析(5) UnitOfWork
本节目录 介绍 分析Abp源码 实现UOW 介绍 UOW(全称UnitOfWork)是指工作单元. 在Abp中,工作单元对于仓储和应用服务方法默认开启.并在一次请求中,共享同一个工作单元. 同时在Ab ...
- [ORM] Entity Framework(1) CodeFirst快速入门
Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案 对象关系映射(英语:Object Relational Mapping ...
- struts2基础——最简单的一个例子
学习版本:struts-2.3.15.3 一.导入jar包,可以参考 官方项目 blank. 二.添加配置文件:web.xml struts.xml web.xml: <filter> & ...
- 【Win10】【译】提交 UWP 应用时遇到意料之外的语言?
原文链接:http://metronuggets.com/2015/12/03/got-unexpected-extra-languages-in-your-uwp-store-submission/ ...
- 【C++】第1章 在VS2015中用C++编写控制台应用程序
分类:C++.VS2015 创建日期:2016-06-12 一.简介 看到不少人至今还在用VC 6.0开发工具学习C++,其实VC 6.0开发工具早就被淘汰了.这里仅介绍学习C++时推荐使用的两种开发 ...