C#winform练习(3)

2018-12-20 15:13

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms; using System.IO;

namespace 图片上翻与下翻 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) {

//设置窗体加载时显示的默认图片 pictureBox1.Image =

Image.FromFile(@\); //设置图片在窗口中如何显示

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; }

//图片路径字段

string[] path = Directory.GetFiles(@\); //图片下标变量 int i = 0; ///

/// 下一张 ///

///

private void button2_Click(object sender, EventArgs e) { i++;

if (i == path.Length) {

i = 0; }

pictureBox1.Image = Image.FromFile(path[i]); }

///

/// 上一张 ///

///

private void button1_Click(object sender, EventArgs e) { i--; if(i<0) {

i = path.Length - 1; }

pictureBox1.Image = Image.FromFile(path[i]); } } }

//9.加载图片并在每分钟更换一张图片如下图: timer控件

Enable:True Interval:1000

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Media;

namespace PictureBow和Timer的小程序 {

public partial class Form1 : Form {

public Form1()

{

InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) {

//播放音乐

SoundPlayer sp = new SoundPlayer();

sp.SoundLocation = @\; sp.Play();

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox6.SizeMode = PictureBoxSizeMode.StretchImage; //在窗体加载的时候给每一个pictureBox都赋值一个图片 pictureBox1.Image =

Image.FromFile(@\); pictureBox2.Image =

Image.FromFile(@\); pictureBox3.Image =

Image.FromFile(@\); pictureBox4.Image =

Image.FromFile(@\); pictureBox5.Image =

Image.FromFile(@\); pictureBox6.Image =

Image.FromFile(@\); }

string [] path = Directory.GetFiles(@\); Random r = new Random();

private void timer1_Tick(object sender, EventArgs e) {

//每隔一秒钟换一张图片

pictureBox1.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox2.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox3.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox4.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox5.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox6.Image = Image.FromFile(path[r.Next(0, path.Length)]); } }

}

//10.目录练习

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.IO;

namespace 目录练习 {

class Program {

static void Main(string[] args) {

//新建文件夹

//Directory.CreateDirectory(@\ //Console.WriteLine(\创建成功\ //Console.ReadKey(); //删除文件夹

//Directory.Delete(@\ //Console.WriteLine(\删除成功\ //Console.ReadKey();

//移动文件夹(必须在同一个根下)

//Directory.Move(@\ //Console.WriteLine(\剪切成功\ //Console.ReadKey();

//获取文件完整目录下的全部文件(指定文件类型显示) //string[] pathfiles =

Directory.GetFiles(@\ //for (int i = 0; i < pathfiles.Length;i++ ) //{ Console.WriteLine(pathfiles[i]); } // Console.ReadKey();

//获取指定目录下所有文件夹的全部路径 //string [] path=

Directory.GetDirectories(@\ // for(int i=0;i

if(Directory.Exists(@\)) {

for (int i=0;i<100;i++) {

Directory.CreateDirectory(@\ + i);

}

Console.ReadKey(); } } } }

//11.做一个简单的浏览器

//在窗体中拖入WebBrowser控件,TextBox控件和一个Botton控件 botton控件

Name:btn Text:转到

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms;

namespace 浏览器控件 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void btn_Click(object sender, EventArgs e) {

string text = textBox1.Text; Uri uri=new Uri(\+text); webBrowser1.Url = uri;


C#winform练习(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:英语图表作文常用句型和结构

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: