![]()
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 对话框控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int b = 0;
public Form1(int a)
{
InitializeComponent();
b = a;
}
private void 字体颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult dr = colorDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
textBox1.ForeColor = colorDialog1.Color;
}
}
private void 选择文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
private void 字体设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowColor = true;
fontDialog1.ShowDialog();
textBox1.Font = fontDialog1.Font;
textBox1.ForeColor = fontDialog1.Color;
}
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "文本文件|*.txt|全部文件|*.*";
DialogResult dr = openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
label1.Text = openFileDialog1.FileName;
StreamReader sr = new StreamReader(openFileDialog1.FileName);
textBox1.Text = sr.ReadToEnd();
//richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
}
string path = "";
private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
{
if (path == "")
{
saveFileDialog1.FileName = "新建文本文件.txt";
saveFileDialog1.ShowDialog();
path = saveFileDialog1.FileName;
}
StreamWriter sw = new StreamWriter(path);
sw.Write(textBox1.Text);
sw.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
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 对话框控件
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
for (int i = 0; i < 3; i++)
{
TextBox t = new TextBox();
flowLayoutPanel1.Controls.Add(t);
}
}
private void 打印设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;
pageSetupDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font f = new Font("宋体",14);
Brush b = new SolidBrush(Color.Black);
PointF p = new PointF(10,10);
e.Graphics.DrawString(textBox1.Text, f, b, p);
}
private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
{
//printPreviewControl1.Document = printDocument1;
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
printDialog1.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(flowLayoutPanel1.Controls.Count.ToString());
}
}
}