C#中2个已经存在的窗体,如何用一个窗体控制另外一个窗体的属性?

pancult 2005-02-18 03:29:50
C#中2个已经存在的窗体,如何用一个窗体控制另外一个窗体的内容??
例如:Form1和Form2 如何用Form2控制Form1里的控件,或者是窗体属性?
...全文
214 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Silverspur 2005-02-18
  • 打赏
  • 举报
回复
学习一下,帮你顶
pancult 2005-02-18
  • 打赏
  • 举报
回复
大家帮忙顶顶吧。有分~~
huizaixingxing 2005-02-18
  • 打赏
  • 举报
回复
up
mobydick 2005-02-18
  • 打赏
  • 举报
回复
http://www.cnblogs.com/zhenyulu/articles/34044.html
看一下吕老师是怎么说的。
pancult 2005-02-18
  • 打赏
  • 举报
回复
求救啊。。各位大哥,我在线等。帮帮忙吧。。
marvelstack 2005-02-18
  • 打赏
  • 举报
回复
简单一点传递引用
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
wtaner20 2005-02-18
  • 打赏
  • 举报
回复
up
xjshuaishuai 2005-02-18
  • 打赏
  • 举报
回复
http://www.cnandusa.com/HArticle2568.aspx
aijing 2005-02-18
  • 打赏
  • 举报
回复
up
yjzhg 2005-02-18
  • 打赏
  • 举报
回复
UP
pancult 2005-02-18
  • 打赏
  • 举报
回复
我是楼主,楼上的误会我意思了
我的2个窗体实际上都已经存在了。都打开了。。
就不能用FORM2 FRM =NEW FORM2();

我这的情况是由 FORM1 打开了 Form2 现在再由Form2回来控制Form1里面的窗体属性或者里面的控件属性
xiongchen 2005-02-18
  • 打赏
  • 举报
回复
新建一个项目,然后添加两个空窗体Form1和Form2,在Form1里添加一个button控件,源码如下,

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication7
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <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.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm=new Form2();
TextBox textBox1=new TextBox();
textBox1.Text="Hello World!";
textBox1.Location=new Point(10,10);
textBox1.Name="NewText";
frm.Controls.Add(textBox1);
frm.Show();
}
}
}
运行程序,将在Form2上添加一个文本框,并将其Text属性设为"Hello World!"
pancult 2005-02-18
  • 打赏
  • 举报
回复
哇,瞬间被排到第2页了,大家帮忙下。能帮忙UP得也有分~~

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧