| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2103 人关注过本帖
标题:[原创]波希知穗的幻灯片
只看楼主 加入收藏
ncy_wisdom
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-7-22
收藏
 问题点数:0 回复次数:3 
[原创]波希知穗的幻灯片
*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: ncy_wisdom E-mail:ncy_wisdom@126.com
*/ 时间: 2007-9-2 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------


今天发了个幻灯片源代码,因为有13张照片,超过了512KB,所以下载的GGJJDDMM请自行添加13张照片在Debug文件夹的Picture中(Picture文件夹自己创建)。

功能:
键盘上的 -> 看下一张图片

键盘上的 <- 看上一张图片

键盘上的 Backspace 返回第一张图片

键盘上的 Enter 退出


大家多捧场啊!!!



代码段:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.IO;

namespace 有趣的窗口
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
///
int num=0; //图片文件数

int i=0; //循环中变化中的图片文件数;

int k=0;

int x=0; //点击空格键的次数

private System.ComponentModel.IContainer components;
public System.Windows.Forms.Timer t;

private Bitmap MyImage;

private System.Windows.Forms.PictureBox p;

string PictureName=null; //本次所用图片名

string[] FileName=new string[11];


public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.t = new System.Windows.Forms.Timer(this.components);
this.p = new System.Windows.Forms.PictureBox();
//
// t
//
this.t.Tick += new System.EventHandler(this.t_Tick);
//
// p
//
this.p.Location = new System.Drawing.Point(0, 0);
this.p.Name = "p";
this.p.TabIndex = 0;
this.p.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(284, 264);
this.FormBorderStyle=FormBorderStyle.None;
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);

this.KeyDown+=new KeyEventHandler(Form1_KeyDown);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

/*private void Form1_Move(object sender, EventArgs e)
{
Point p=new Point(0,0);
this.Location=p;
}*/

/*private void Form1_LostFocus(object sender, EventArgs e)
{
this.Activate();
//this.WindowState=FormWindowState.Maximized;
}*/

private void Form1_Load(object sender, System.EventArgs e)
{
t.Interval=3000;
t.Enabled=true;

GetName();

ShowMyImage(ChangeName(),this.ClientSize.Width,this.ClientSize.Height);
//t.Enabled=false;


}

private void t_Tick(object sender, EventArgs e)
{
//Thread.Sleep(1000);
ShowMyImage(ChangeName(),this.ClientSize.Width,this.ClientSize.Height);
}

public void ShowMyImage(String fileToDisplay, int xSize, int ySize)
{
// Sets up an image object to be displayed.
if (MyImage != null)
{
MyImage.Dispose();
}

// Stretches the image to fit the pictureBox.
p.SizeMode = PictureBoxSizeMode.StretchImage ;
MyImage = new Bitmap(fileToDisplay);
p.ClientSize = new Size(xSize, ySize);
p.Image = (Image) MyImage ;

this.Controls.Add(p);
}

private string ChangeName()
{
PictureName=FileName[k];

if(k<10)
{
k++;
}
else
{
k=0;
}
return PictureName;
}


//得到文件数
private void GetNameNum()
{
string name=null;
foreach (string fileName in Directory.GetFiles("Picture"))
{
name=fileName.Substring(fileName.LastIndexOf(@".")+1);

if (name=="jpg")
{
num++;
}
else
{
num=num;
}
}
}

//将文件名装入FileName[]中
private void GetName()
{
GetNameNum();
string name=null;


foreach (string fileName in Directory.GetFiles("Picture"))
{
name=fileName.Substring(fileName.LastIndexOf(@".")+1);

if (name=="jpg")
{
FileName[i]=fileName;
//MessageBox.Show(FileName[i]);
i++;

}
else
{
num=num;
}
}
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
this.Close();
}
else if (e.KeyCode==Keys.Space)
{
if (parity(x))
{
t.Enabled=true;
}
else
{
t.Enabled=false;
}
x++;
}
else if (e.KeyCode==Keys.Right)
{
ShowMyImage(ChangeName(),this.ClientSize.Width,this.ClientSize.Height);
}

else if (e.KeyCode==Keys.Left)
{
if (k>1)
{
k=k-2;
}
else
{
k=0;
}

ShowMyImage(ChangeName(),this.ClientSize.Width,this.ClientSize.Height);
}

else if (e.KeyCode==Keys.Back)
{
k=0;
ShowMyImage(ChangeName(),this.ClientSize.Width,this.ClientSize.Height);
}
}

//辨别奇偶性
private static bool parity(int i)
{
if (i%2==0)
{
return true;
}
else
return false;
}
}
}

搜索更多相关主题的帖子: 幻灯片 
2007-09-02 19:48
andey
Rank: 2
等 级:新手上路
威 望:4
帖 子:938
专家分:0
注 册:2007-7-18
收藏
得分:0 
支持一下!!!

msdn == 葵花宝典!!!
QQ:122768959
2007-10-19 15:29
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
支持开源

愛生活 && 愛編程
2007-10-19 15:31
反正都是自我
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2007-7-27
收藏
得分:0 

好,正在做图片这方面的程序。。


2007-10-19 15:34
快速回复:[原创]波希知穗的幻灯片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015666 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved