zoukankan      html  css  js  c++  java
  • C#中如何定义全局变量及在各窗体中使用全局变量

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using System.IO;
    
    namespace NewTest
    {
    	public class PublicValue
    	{
    		public static string FileName;
    		public static int[] aa;
    	}
    	/// <summary>
    	/// Description of MainForm.
    	/// </summary>
    	public partial class MainForm : Form
    	{
    		
    		public MainForm()
    		{
    			//
    			// The InitializeComponent() call is required for Windows Forms designer support.
    			//
    			InitializeComponent();
    			
    			//
    			// TODO: Add constructor code after the InitializeComponent() call.
    			//
    		}
    		
    		void MainFormLoad(object sender, EventArgs e)
    		{
    			this.Width=Screen.PrimaryScreen.WorkingArea.Width;
    			this.Height =Screen.PrimaryScreen.WorkingArea.Height;
    			this.Left =Screen.PrimaryScreen.WorkingArea.Left;			
    			this.Top =Screen.PrimaryScreen.WorkingArea.Top;			
    		}
    		
    		void Button1Click(object sender, EventArgs e)
    		{			
    			PublicValue.aa=new int[10];
    			PublicValue.aa[0]=10;
    			PublicValue.FileName="dfjlkjkldfsjl";
    		}
    	}
    }
    

    以上定义的publicValue类,其中的变量可以在同一个命名空间中使用,包括在子窗体或非子窗口中调用。

  • 相关阅读:
    单元测试练习
    对软件的看法
    个人最终总结
    论文笔记--Fast RCNN
    个人最终总结2
    结对编程--基于android平台的黄金点游戏(2.0版本)
    结对编程--基于android平台的黄金点游戏
    团队作业(一)
    [java]wordcount程序
    第三周作业(二)
  • 原文地址:https://www.cnblogs.com/China3S/p/6123454.html
Copyright © 2011-2022 走看看