35. Common dialog box
Different Windows applications often use the same dialog boxes, such as open, save, and print dialogs, which are called common dialog boxes. Let's learn about the 6 common dialog boxes: message box (Messagebox), Open File Dialog (OpenFileDialog), Save File Dialog (SaveFileDialog), Color dialog box (colordialog), The Font dialog box (fontdialog) and the Print dialog box (Printdialog).
1. Message box
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 WindowsFormsApplication25
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
DialogResult result;
if (This.textBox1.Text = = "Guojun66")
{
MessageBox.Show (this, "password correct", "hint", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Else
{
result = MessageBox.Show (this, "Password error", "hint", messageboxbuttons.retrycancel,messageboxicon.information);
if (result = = Dialogresult.retry)
{
This.textBox1.Text = "";
This.textBox1.Focus ();
}
Else
{
Application.exit ();
}
}
}
private void Form1_Load (object sender, EventArgs e)
{
TextBox1.Text = "";
}
private void Button2_Click (object sender, EventArgs e)
{
Application.exit ();
}
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6B/6E/wKiom1UtB8HiTpPsAACtU1714IU518.jpg "title=" v0%0 Dtl~3fffnt93hco1bw4.png "alt=" Wkiom1utb8hitppsaactu1714iu518.jpg "/>
2. Open and save the file.
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 WindowsFormsApplication26
{
public partial class Form1:form
{
OpenFileDialog OpenFileDialog = new OpenFileDialog ();
SaveFileDialog SaveFileDialog = new SaveFileDialog ();
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
if (openfiledialog.showdialog () = = DialogResult.OK)
MessageBox.Show ("Open file \ n" + openfiledialog.filename, "Open File",
Messageboxbuttons.ok,messageboxicon.information);
}
private void Button2_Click (object sender, EventArgs e)
{
if (savefiledialog.showdialog () = = DialogResult.OK)
{
MessageBox.Show ("Saved file \ n" + savefiledialog.filename, "Save File",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6B/6A/wKioL1UtDXygpUxGAADdRSA6Pl0594.jpg "title=" $KJ 0[ 762nlz]loxpwb]p]w3.png "alt=" Wkiol1utdxygpuxgaaddrsa6pl0594.jpg "/>
3. Color selection dialog box
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 WindowsFormsApplication27
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
ColorDialog ColorDialog = new ColorDialog ();
Colordialog.customcolors = new int[]
{
0x0000ff,0xff0000,0xff00ff,0xffff00,0xffffff
};
Colordialog.allowfullopen = false;
if (colordialog.showdialog () = = DialogResult.OK)
{
BackColor = Colordialog.color;
}
}
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/6A/wKioL1UtD2Gy5HVfAACICjEIzZ4346.jpg "title=" TE ' 57taaf% (t_6356 (e_8l7.png "alt=" Wkiol1utd2gy5hvfaacicjeizz4346.jpg "/>
4. Font dialog box
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 WindowsFormsApplication28
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
FontDialog FontDialog = new FontDialog ();
FontDialog. Showcolor = true;
FontDialog. Allowscriptchange = true;
FontDialog. Allowvectorfonts = true;
FontDialog. Showeffects = true;
if (FontDialog. ShowDialog () = = DialogResult.OK)
{
This.textBox1.Font = FontDialog. Font;
This.textBox1.ForeColor = FontDialog. Color;
}
}
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6B/6F/wKiom1UtEFui2-Q9AACPERsv8p0138.jpg "title=" D (Nauf $WIC 6h@}we%tpu9vq.png "alt=" Wkiom1utefui2-q9aacpersv8p0138.jpg "/>
5. Print dialog box
Not common, it is not introduced.
This article from "Very blog" blog, reproduced please contact the author!
C # Self-study Road 35