Example of PictureBox Control, colorDialog, openDialog and saveDialog control.
Add a colorDialog, fontDialog, openFileDialog and saveDialog to the form and design as following :
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; namespace WinForms7 { public partial class Form7 : Form { public Form7() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DialogResult dr = colorDialog1.ShowDialog(); if (dr == DialogResult.OK) button1.BackColor = colorDialog1.Color; } private void button2_Click(object sender, EventArgs e) { DialogResult dr = fontDialog1.ShowDialog(); if (dr == DialogResult.OK) button2.Font = fontDialog1.Font; } private void button3_Click(object sender, EventArgs e) { openFileDialog1.FileName = " "; openFileDialog1.Filter = "ImageFiles(*.jpg)|*.jpg|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*"; DialogResult dr = openFileDialog1.ShowDialog(); if (dr != DialogResult.Cancel) pictureBox1.ImageLocation = openFileDialog1.FileName; } private void button4_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "ImageFiles(*.jpg)|*.jpg|Icon Files(*.ico)|*.ico|All Files(*.*)|*.*"; DialogResult dr = saveFileDialog1.ShowDialog(); if (dr != DialogResult.Cancel) { string fname = saveFileDialog1.FileName; pictureBox1.Image.Save(fname); } } } }
No comments:
Post a Comment