zoukankan      html  css  js  c++  java
  • VisualC#中实现窗体间的数据传递之一

    作者:马金虎 来自:网络
    一个稍微复杂一点的程序一般都有二个或者更多的窗体。有时在程序设计中,数据不仅要在同一个窗体中传递,还要在窗体间传递,这种传递是主窗体与从窗体之间数据的互相传递。从本文开始,我们将列举不同窗体间数据传递的四种情况,和用Visual C#实现这四种情况的具体方法。下面先介绍用Visual C#实现窗体间传递数据中第一种情况——从主窗体向从窗体传递字符串。在阅读完本文后,你还尝试一下利用此方法在窗体间传送数值等数据。

    本文中程序设计、调试、运行的软件环境:

    Windows2000 服务器版

    Visual Studio.Net正式版,.Net FrameWork SDK版本号3705

    实现步骤:

    1.启动Visual Studio .Net

    2.选择菜单【文件】|【新建】|【项目】后,弹出【新建项目】对话框

    3.将【项目类型】设置为【Visual C#项目】

    4.将【模板】设置为【控制台应用程序】

    5.在【名称】文本框中输入【VC#中不同窗体数据传递方法01】

    6.在【位置】的文本框中输入【E:\VS.NET项目】,然后单击【确定】按钮,这样VC#中不同窗体数据传递方法01项目就创建完成了

    7.把Visual Studio.Net的当前窗口切换到【Form1.cs(设计)】窗口,并从【工具箱】中的【Windows窗体】选项卡中拖入下列组件到【Form1.cs(设计)】窗体中,并执行相应操作:

    · 二个TextBox组件,用以输入向Form2窗体传送的数据

    · 二个Label组件

    · 一个Button组件,名称为button1,并在拖入【Form1.cs(设计)】窗体后,双击它,则Visual Stuido .Net产生其Click事件对应的处理代码。

    8.把Visual Studio .Net的当前窗口切换到【Form1.cs】窗口,即:Form1.cs的代码编辑窗口。并用下列代码替换替代系统产生的InitializeComponent过程。


    private void InitializeComponent ( )
     {
    this.button1 = new System.Windows.Forms.Button ( ) ;
    this.textBox1 = new System.Windows.Forms.TextBox ( ) ;
     this.textBox2 = new System.Windows.Forms.TextBox ( ) ;
    this.label1 = new System.Windows.Forms.Label ( ) ;
    this.label2 = new System.Windows.Forms.Label ( ) ;
    this.SuspendLayout ( ) ;
    this.button1.Location = new System.Drawing.Point ( 103 , 149 ) ;
    this.button1.Name = "button1" ;
    this.button1.Size = new System.Drawing.Size ( 75 , 36 ) ;
    this.button1.TabIndex = 0 ; this.button1.Text = "发送" ;
    this.button1.Click += new System.EventHandler ( this.button1_Click ) ; this.textBox1.Location = new System.Drawing.Point ( 93 , 56 ) ; this.textBox1.Name = "textBox1" ; this.textBox1.Size = new System.Drawing.Size ( 122 , 21 ) ; this.textBox1.TabIndex = 1 ; this.textBox1.Text = "" ; this.textBox2.Location = new System.Drawing.Point ( 93 , 99 ) ; this.textBox2.Name = "textBox2" ; this.textBox2.Size = new System.Drawing.Size ( 123 , 21 ) ; this.textBox2.TabIndex = 2 ; this.textBox2.Text = "" ; this.label1.Location = new System.Drawing.Point ( 29 , 57 ) ; this.label1.Name = "label1" ; this.label1.TabIndex = 3 ; this.label1.Text = "欢迎词:" ; this.label2.Location = new System.Drawing.Point ( 16 , 100 ) ; this.label2.Name = "label2" ; this.label2.TabIndex = 4 ; this.label2.Text = "提示信息:" ; this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ; this.ClientSize = new System.Drawing.Size ( 263 , 223 ) ; this.Controls.AddRange ( new System.Windows.Forms.Control[ ] { this.textBox2 , this.textBox1 , this.button1 , this.label2 , this.label1 } ) ; this.Name = "Form1" ; this.Text = "Form1" ; this.Load += new System.EventHandler ( this.Form1_Load ) ; this.ResumeLayout ( false ) ; }
  • 相关阅读:
    订单生成案例详解
    分页案例详解
    简单的多条件查询案例
    删除选中案例详解
    转账汇款案例
    登录操作记住用户名实现
    根据自定义异常来回显错误信息
    会话技术cookie和session详解
    JDBC
    Netty入门教程——认识Netty
  • 原文地址:https://www.cnblogs.com/terrylin/p/439848.html
Copyright © 2011-2022 走看看