博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多窗口创建控件
阅读量:6082 次
发布时间:2019-06-20

本文共 2938 字,大约阅读时间需要 9 分钟。

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;
using System.IO;

 

namespace wht

{
    public partial class Form1 : Form
    {
        private static int FormCount = 0;

        public Form1()

        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)

        {
            string path = @"c:\temp\MyTest.txt";
           
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (StreamWriter sw = new StreamWriter(path))

                {
                    sw.WriteLine("This");
                    sw.WriteLine("is some textvbbnvnvncfdh");
                    sw.WriteLine("to test");
                    sw.WriteLine("Reading");
                }

                using (StreamReader sr = new StreamReader(path))

                {
                    string tt = "";
                    while (sr.Peek() >= 0)
                    {
                       // Console.WriteLine(sr.ReadLine());
                       tt += sr.ReadLine() + "\n";
                    }
                    MessageBox.Show(tt);
                }
              
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)

        {

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

        {

        }

        private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)

        {
            Form frmTemp = new Form();
          
           // Button button1 = new Button ();
           // Button button2 = new Button ();
           // button1.Text = "OK";
           // button1.Location = new Point (10, 10);
           // button2.Text = "Cancel";
           // button2.Location
           

 

            //frmTemp.MdiParent = this;

           // frmTemp.Text = "window#" + FormCount.ToString();
            //FormCount++;
           // frmTemp.Controls.Add(button1);
            //frmTemp.Controls.Add(button2);
            //frmTemp.Show();

            // Create a new instance of the form.

            Form form1 = new Form();

            form1.MdiParent = this;

            // Create two buttons to use as the accept and cancel buttons.
            Button button1 = new Button();
            Button button2 = new Button();

            // Set the text of button1 to "OK".

            button1.Text = "OK";
            // Set the position of the button on the form.
            button1.Location = new Point(10, 10);
            // Set the text of button2 to "Cancel".
            button2.Text = "Cancel";
            // Set the position of the button based on the location of button1.
            button2.Location
               = new Point(button1.Left, button1.Height + button1.Top + 10);
            // Set the caption bar text of the form.  
            form1.Text = "My Dialog Box";
            // Display a help button on the form.
            form1.HelpButton = true;

            // Define the border style of the form to a dialog box.

            form1.FormBorderStyle = FormBorderStyle.FixedDialog;
            // Set the MaximizeBox to false to remove the maximize box.
            form1.MaximizeBox = false;
            // Set the MinimizeBox to false to remove the minimize box.
            form1.MinimizeBox = false;
            // Set the accept button of the form to button1.
            form1.AcceptButton = button1;
            // Set the cancel button of the form to button2.
            form1.CancelButton = button2;
            // Set the start position of the form to the center of the screen.
            form1.StartPosition = FormStartPosition.CenterScreen;

            // Add button1 to the form.

            form1.Controls.Add(button1);
            // Add button2 to the form.
            form1.Controls.Add(button2);

            // Display the form as a modal dialog box.

            form1.Show();

           

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

    }

}

转载地址:http://fvkwa.baihongyu.com/

你可能感兴趣的文章
BABOK - 企业分析(Enterprise Analysis)概要
查看>>
Linux 配置vnc,开启linux远程桌面
查看>>
NLog文章系列——如何优化日志性能
查看>>
Hadoop安装测试简单记录
查看>>
CentOS6.4关闭触控板
查看>>
ThreadPoolExecutor线程池运行机制分析-线程复用原理
查看>>
React Native 极光推送填坑(ios)
查看>>
Terratest:一个用于自动化基础设施测试的开源Go库
查看>>
修改Windows远程终端默认端口,让服务器更安全
查看>>
扩展器必须,SAS 2.0未必(SAS挺进中端存储系统之三)
查看>>
Eclipse遇到Initializing Java Tooling解决办法
查看>>
while((ch = getchar()) != '\n')
查看>>
好程序员web前端分享JS检查浏览器类型和版本
查看>>
Oracle DG 逻辑Standby数据同步性能优化
查看>>
exchange 2010 队列删除
查看>>
「翻译」逐步替换Sass
查看>>
H5实现全屏与F11全屏
查看>>
处理excel表的列
查看>>
C#数据采集类
查看>>
quicksort
查看>>