社区
C#
帖子详情
在A窗体调用B窗体时如果调用B窗体的参数啊?
laojx
2006-03-12 09:31:03
通常是先建立好A窗体,然后再建立B窗体,我想在A窗体调用B窗体,我变在A窗体的代码中把B窗体给“NEW”出来,但是发现有些b窗体的参数调不过来,因为它建立时全默认为private类型的,我只有把用到的B窗体的参数到B窗体里把它改成Public型,这样岂不是很麻烦,请问大家是不是我的操作有问题?还是有其它更简便的方法?
...全文
135
6
打赏
收藏
在A窗体调用B窗体时如果调用B窗体的参数啊?
通常是先建立好A窗体,然后再建立B窗体,我想在A窗体调用B窗体,我变在A窗体的代码中把B窗体给“NEW”出来,但是发现有些b窗体的参数调不过来,因为它建立时全默认为private类型的,我只有把用到的B窗体的参数到B窗体里把它改成Public型,这样岂不是很麻烦,请问大家是不是我的操作有问题?还是有其它更简便的方法?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
真相重于对错
2006-03-13
打赏
举报
回复
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;
}
}
}
真相重于对错
2006-03-13
打赏
举报
回复
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 );
}
}
}
}
真相重于对错
2006-03-13
打赏
举报
回复
事件
達魔
2006-03-13
打赏
举报
回复
你的问题其实不是“问题”,这是类封装的基本特性,
在类定义时,域的默认访问属性就是private,即是私有的,只有类的成员才可以访问它,你想在该类以外的地方使用这些域那么你只能修改该域的访问属性,把它变成public类型,或者再定义一个属性与该域对应上,至于是只读的还是可写的属性根据你的要求来定,但这个属性肯定也得是public访问属性才可以。
Kshatriya
2006-03-13
打赏
举报
回复
csdn搜索
marvelstack
2006-03-12
打赏
举报
回复
试一下,
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
英语900句1.0
采用顶条技术,不知不觉学英语口语,提供源代码 采用主要技术如下: 1、顶条技术 2、发音引擎使用 3、特异
窗体
使用及拖动 4、使用资源文件 5、API函数
调用
源程序有详细注释
winform利用委托实现A
窗体
调用
B
窗体
的方法
1.在A
窗体
FrmUserAdd中声明指向FrmUserManager
窗体
中的BindUsers方法指针(委托) ...2.在B
窗体
FrmUserManage打开A
窗体
FrmUserAdd事件中把方法BindUsers赋值给A
窗体
的指针(委托) private void butto...
winform中A
窗体
调用
B
窗体
的方法
1.FrmUserAdd
窗体
调用
FrmUserManager
窗体
的BindUsers()方法 可以把
窗体
当做类。即FrmUserAdd类要
调用
FrmUserManager类中的BindUsers()方法 2.需要把BindUsers()方法设置为public #region 绑定用户信息 public ...
WPF 委托 事件 B
窗体
调用
A
窗体
方法
具体实现 A
窗体
中加载B
窗体
B
窗体
触发A
窗体
里的方法 当点击B
窗体
确定Button事件 给A
窗体
俩个TextBox赋值 并关闭B
窗体
B
窗体
1)定义
参数
类 2)定义委托 定义委托事件 3) 定义触发事件方法 4) 触发事件...
C#一个
窗体
调用
另一个
窗体
的方法
一个
窗体
调用
另一个
窗体
的方法:例如:
窗体
B要
调用
窗体
A中的方法1、首先在
窗体
A中将
窗体
A设为静态
窗体
public static FormA m_formA; //设此
窗体
为静态,其他
窗体
可
调用
此
窗体
中的方法2、然后在此
窗体
A的构造函数中...
C#
111,125
社区成员
642,540
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章