zoukankan      html  css  js  c++  java
  • 多窗口创建控件

    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)
            {

            }

        }
    }

  • 相关阅读:
    【洛谷P1948】[USACO08JAN]电话线
    【洛谷P1967】[NOIP2013]货车运输
    【题解】洛谷P2926 [USACO08DEC]拍头Patting Heads
    【题解】洛谷P1495 曹冲养猪 (中国剩余定理)
    【题解】POJ1845 Sumdiv(乘法逆元+约数和)
    【题解】P1516 青蛙的约会(Exgcd)
    【数论】同余问题
    DP Cleaning Up 打扫卫生
    set+链表 【POJ Challenge】生日礼物
    并查集 [Scoi2010]游戏
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2240339.html
Copyright © 2011-2022 走看看