CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

在A窗体调用B窗体时如果调用B窗体的参数啊?

楼主laojx(星宇)2006-03-12 21:31:03 在 .NET技术 / C# 提问

通常是先建立好A窗体,然后再建立B窗体,我想在A窗体调用B窗体,我变在A窗体的代码中把B窗体给“NEW”出来,但是发现有些b窗体的参数调不过来,因为它建立时全默认为private类型的,我只有把用到的B窗体的参数到B窗体里把它改成Public型,这样岂不是很麻烦,请问大家是不是我的操作有问题?还是有其它更简便的方法? 问题点数:20、回复次数:6Top

1 楼zhzuo(秋枫)回复于 2006-03-12 22:29:45 得分 10

试一下,  
  http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspxTop

2 楼Kshatriya(何以解忧,惟有杜康)回复于 2006-03-13 02:12:41 得分 0

csdn搜索Top

3 楼ThreadSharp(ThreadSharp V2006)回复于 2006-03-13 08:33:03 得分 0

你的问题其实不是“问题”,这是类封装的基本特性,  
  在类定义时,域的默认访问属性就是private,即是私有的,只有类的成员才可以访问它,你想在该类以外的地方使用这些域那么你只能修改该域的访问属性,把它变成public类型,或者再定义一个属性与该域对应上,至于是只读的还是可写的属性根据你的要求来定,但这个属性肯定也得是public访问属性才可以。Top

4 楼hdt(倦怠)回复于 2006-03-13 08:37:47 得分 10

事件  
  Top

5 楼hdt(倦怠)回复于 2006-03-13 09:10:59 得分 0

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
   
  namespace   testeventForm  
  {  
  ///   <summary>  
  ///   Form2   的摘要说明。  
  ///   </summary>  
  public   class   Form2   :   System.Windows.Forms.Form  
  {  
  public   delegate   void   Eventhander(   string   str   );  
  public   event   Eventhander   onEvent;  
  private   System.Windows.Forms.TextBox   textBox1;  
  private   System.Windows.Forms.Button   button1;  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form2()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if(components   !=   null)  
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.textBox1   =   new   System.Windows.Forms.TextBox();  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.SuspendLayout();  
  //    
  //   textBox1  
  //    
  this.textBox1.Location   =   new   System.Drawing.Point(88,   24);  
  this.textBox1.Name   =   "textBox1";  
  this.textBox1.TabIndex   =   0;  
  this.textBox1.Text   =   "textBox1";  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(104,   64);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   1;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   Form2  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(292,   273);  
  this.Controls.Add(this.button1);  
  this.Controls.Add(this.textBox1);  
  this.Name   =   "Form2";  
  this.Text   =   "Form2";  
  this.Load   +=   new   System.EventHandler(this.Form2_Load);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  private   void   Form2_Load(object   sender,   System.EventArgs   e)  
  {  
   
  }  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  if(   this.onEvent   !=   null   )  
  {  
  this.onEvent(   this.textBox1.Text   );  
  }  
  }  
  }  
  }  
  Top

6 楼hdt(倦怠)回复于 2006-03-13 09:11:34 得分 0

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
   
  namespace   testeventForm  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   button1;  
  private   System.Windows.Forms.TextBox   textBox1;  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.textBox1   =   new   System.Windows.Forms.TextBox();  
  this.SuspendLayout();  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(120,   56);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   0;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   textBox1  
  //    
  this.textBox1.Location   =   new   System.Drawing.Point(112,   24);  
  this.textBox1.Name   =   "textBox1";  
  this.textBox1.TabIndex   =   1;  
  this.textBox1.Text   =   "textBox1";  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(292,   273);  
  this.Controls.Add(this.textBox1);  
  this.Controls.Add(this.button1);  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.Load   +=   new   System.EventHandler(this.Form1_Load);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
  private   void   Form1_Load(object   sender,   System.EventArgs   e)  
  {  
   
  }  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  Form2   f2   =   new   Form2();  
  f2.onEvent   +=   new   testeventForm.Form2.Eventhander(f2_onEvent);  
  f2.Show();  
  }  
  private   void   f2_onEvent(   string   str   )  
  {  
  this.textBox1.Text   =   str;  
  }  
   
  }  
  }  
  Top

相关问题

  • 窗体调用
  • 窗体名作为参数如何调用?
  • 如何在子窗体中调用父窗体的方法,并把参数传过去
  • 急!如何在函数中使用参数,此参数是某个窗体元素的id,然后实现此窗体元素的调用
  • dll中的窗体调用
  • 如何调用窗体!
  • VB 窗体调用FORM.HIDE
  • 窗体的调用问题
  • .net 窗体调用问题?
  • 关于窗体的调用

关键词

  • 代码
  • 属性
  • 窗体
  • 调用
  • textbox
  • button
  • onevent
  • disposing
  • eventhander
  • testeventform

得分解答快速导航

  • 帖主:laojx
  • zhzuo
  • hdt

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo