一、容器标签
布局:
Anchor:锁定位置,指定与窗口容器的边缘位置,会随着窗口大小的改变而改变;
Dock:填充窗口的位置。一般与容器标签同时使用。
1、Panel:对控件进行分组。可以独立布局,里面可以放其他控件和容器(包括自身)再进行布局。
2、FlowLayOutPanel:流式布局标签。从左到右。宽度不够,自动换行。
3、GroupBox:分组容器。拥有panel全部属性,比panel多了个标题和边框样式。
4、Tabcontrol:选项卡容器。
5、SplitContainer:二分区容器。将容器分为两部分,这两个分部分,用户可以随意调节其大小。选中整体容器,可以修改Oriention属性来调节分割的区域是水平的还是垂直的。
6、TableLayout:表格容器。每个表格只能放一个控件,可以先放一个容器,再放多个控件。
二、打印标签
把要打印的文字放在一个对象a(printDocument)上,打印的操作就是对a的操作。
PageSetupDialog:打印设置对话框
PrintPreviewControl:打印预览控件
PrintPreviewDialog:打印预览对话框
PrintDialog:打印对话框
DialogResult dr = printDialog1.ShowDialog();
if (dr == DialogResult.OK)//如果用户点击的是确定按钮,那么执行打印
{
printDocument1.Print();
}
DialogResult是一个可被实例化的枚举类,用来接收用户在对话框中的操作
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.Drawing;//设置printDocument时需要这个命名空间 namespace WindowsFormsApplication20 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { } private void groupBox1_Enter(object sender, EventArgs e) { } private void radioButton1_CheckedChanged(object sender, EventArgs e) { } private void radioButton2_CheckedChanged(object sender, EventArgs e) { } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void 打印设置toolStripMenuItem1_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("黑体",20); SolidBrush s=new SolidBrush(Color.Blue); e.Graphics.DrawString(textBox1.Text,f,s,10,10);//设置盛有要打印内容的对象 } private void toolStripMenuItem2_Click(object sender, EventArgs e)//打印预览 { printPreviewControl1.Document = printDocument1;//将要打印的对象放到预览上 } private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) { } private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { } private void 打印PToolStripMenuItem_Click(object sender, EventArgs e) { printDialog1.Document = printDocument1;//将盛有打印内容的对象给打印窗口 DialogResult s= printDialog1.ShowDialog();//接受打印结果 if (s == DialogResult.OK)//如果选择确定 { printDocument1.Print(); } } } }