изображение по умолчанию
Добавьте на форму элемент управления PictureBox. Раскройте бермудский треугольник. Нажмите на Choose Image.
В диалоговом окне нажмите на кнопку Import.
Выберите изображение.
Нажмите OK.
Результат работы программы.
изображение выбирает пользователь
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0053 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
openFileDialog1.Filter ="Images (*.jpg; *.jpeg; *.gif; *.bmp; *.ico; *.png) | *.jpg; *.jpeg; *.gif; *.bmp; *.ico; *.png"; -
if(openFileDialog1.ShowDialog() == DialogResult.OK) { -
Bitmap myImage =newBitmap(openFileDialog1.FileName); -
//если размер изображения больше PictureBox,отображаем изображение в режиме Zoom -
if(myImage.Size.Height > pictureBox1.Size.Height & myImage.Size.Width > pictureBox1.Size.Width) { -
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; -
pictureBox1.Image = (Image)myImage; -
} -
//если размер изображения меньше или равен PictureBox,отображаем изображение в режиме CenterImage -
else{ -
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; -
//обязательно привести к типу Image -
pictureBox1.Image = (Image)myImage; -
} -
} -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0053 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
openFileDialog1.Filter ="Images (*.jpg; *.jpeg; *.gif; *.bmp; *.ico; *.png) | *.jpg; *.jpeg; *.gif; *.bmp; *.ico; *.png"; -
if(openFileDialog1.ShowDialog() == DialogResult.OK) { -
Bitmap myImage =newBitmap(openFileDialog1.FileName); -
//если размер изображения больше PictureBox,отображаем изображение в режиме Zoom -
if(myImage.Size.Height > pictureBox1.Size.Height & myImage.Size.Width > pictureBox1.Size.Width) { -
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; -
pictureBox1.Image = (Image)myImage; -
} -
//если размер изображения меньше или равен PictureBox,отображаем изображение в режиме CenterImage -
else{ -
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; -
//обязательно привести к типу Image -
pictureBox1.Image = (Image)myImage; -
} -
} -
} -
} }
слайдер
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0054 {-
publicpartialclassForm1 : Form { -
//количество файлов -
intamount = 8; -
//массив путей файлов -
string[] arra; -
//индекс массива -
intindex = 0; -
//метод заполняет массив -
voidCreateArray() { -
//имя файла -
intname = 1; -
arra =newstring[amount]; -
for(inti=0; i<arra.Length; i++) { -
arra[i] =@"img/"+ name++ +".jpg"; -
} -
} -
publicForm1() { -
InitializeComponent(); -
} -
//кнопка Start -
privatevoidbutton1Start_Click(objectsender, EventArgs e) { -
timer1.Start(); -
} -
//кнопка Stop -
privatevoidbutton2Stop_Click(objectsender, EventArgs e) { -
timer1.Stop(); -
} -
//таймер -
privatevoidtimer1_Tick(objectsender, EventArgs e) { -
CreateArray(); -
if(index >= arra.Length) { -
index = 0; -
} -
Bitmap myImage =newBitmap(arra[index++]); -
label1.Text = index.ToString(); -
pictureBox1.Image = (Image)myImage; -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0054 {-
publicpartialclassForm1 : Form { -
//количество файлов -
intamount = 8; -
//массив путей файлов -
string[] arra; -
//индекс массива -
intindex = 0; -
//метод заполняет массив -
voidCreateArray() { -
//имя файла -
intname = 1; -
arra =newstring[amount]; -
for(inti=0; i<arra.Length; i++) { -
arra[i] =@"img/"+ name++ +".jpg"; -
} -
} -
publicForm1() { -
InitializeComponent(); -
} -
//кнопка Start -
privatevoidbutton1Start_Click(objectsender, EventArgs e) { -
timer1.Start(); -
} -
//кнопка Stop -
privatevoidbutton2Stop_Click(objectsender, EventArgs e) { -
timer1.Stop(); -
} -
//таймер -
privatevoidtimer1_Tick(objectsender, EventArgs e) { -
CreateArray(); -
if(index >= arra.Length) { -
index = 0; -
} -
Bitmap myImage =newBitmap(arra[index++]); -
label1.Text = index.ToString(); -
pictureBox1.Image = (Image)myImage; -
} -
} }