• winfrom 对话框


    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());
            }
        }
    }
  • 相关阅读:
    22.json&pickle&shelve
    22.BASE_DIR,os,sys
    21.time和random
    21.模块的执行以及__name__
    21.python的模块(Module)和包(Package)
    21. 对文件进行查询修改等操作
    20.装饰器和函数闭包
    19.python基础试题(三)
    19.生产者消费者模型
    19.yield和send的区别
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5640549.html
Copyright © 2020-2023  润新知