Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:3k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Windows.Forms;
  7. using System.Data;
  8. using System.Threading;
  9. using System.Security;
  10. namespace SecurityApp9
  11. {
  12.    /// <summary>
  13.    /// Summary description for Form1.
  14.    /// </summary>
  15.    public class Form1 : System.Windows.Forms.Form
  16.    {
  17.       private System.Windows.Forms.ListBox listBox1;
  18.       private System.Windows.Forms.Button button1;
  19.       /// <summary>
  20.       /// Required designer variable.
  21.       /// </summary>
  22.       private System.ComponentModel.Container components;
  23.       public Form1()
  24.       {
  25.          //
  26.          // Required for Windows Form Designer support
  27.          //
  28.          InitializeComponent();
  29.       }
  30.       /// <summary>
  31.       /// Clean up any resources being used.
  32.       /// </summary>
  33.       protected override void Dispose(bool disposing)
  34.       {
  35.          if( disposing )
  36.          {
  37.             if (components != null) 
  38.             {
  39.                components.Dispose();
  40.             }
  41.          }
  42.          base.Dispose( disposing );
  43.       }
  44. #region Windows Form Designer generated code
  45.       /// <summary>
  46.       /// Required method for Designer support - do not modify
  47.       /// the contents of this method with the code editor.
  48.       /// </summary>
  49.       private void InitializeComponent()
  50.       {
  51.          this.listBox1 = new System.Windows.Forms.ListBox();
  52.          this.button1 = new System.Windows.Forms.Button();
  53.          this.SuspendLayout();
  54.          // 
  55.          // listBox1
  56.          // 
  57.          this.listBox1.Location = new System.Drawing.Point(8, 8);
  58.          this.listBox1.Name = "listBox1";
  59.          this.listBox1.Size = new System.Drawing.Size(280, 199);
  60.          this.listBox1.TabIndex = 0;
  61.          // 
  62.          // button1
  63.          // 
  64.          this.button1.Location = new System.Drawing.Point(104, 224);
  65.          this.button1.Name = "button1";
  66.          this.button1.TabIndex = 1;
  67.          this.button1.Text = "Load Data";
  68.          this.button1.Click += new System.EventHandler(this.button1_Click);
  69.          // 
  70.          // Form1
  71.          // 
  72.          this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  73.          this.ClientSize = new System.Drawing.Size(296, 253);
  74.          this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1,
  75.                                                                       this.listBox1});
  76.          this.Name = "Form1";
  77.          this.Text = "Form1";
  78.          this.ResumeLayout(false);
  79.       }
  80. #endregion
  81.       /// <summary>
  82.       /// The main entry point for the application.
  83.       /// </summary>
  84.       [STAThread]
  85.       static void Main() 
  86.       {
  87.          Application.Run(new Form1());
  88.       }
  89.       private void button1_Click(object sender, System.EventArgs e)
  90.       {
  91.          try
  92.          {
  93.             StreamReader din = File.OpenText(@"c:animals.txt");             String str;             while ((str=din.ReadLine()) != null) 
  94.             {                listBox1.Items.Add(str);             }          }          catch          {             listBox1.Items.Add("Permission denied accessing file");          }       }
  95.    }
  96. }