两个窗口之间的问题

fjtxwd 2009-08-08 04:58:58
form1中有一个listbox和一个button
form2中有一个textbox和一个button
点击form1的button弹出form2,然后在form2的textbox中输入一个字符串,按form2的button后能添加到form1的listbox中
form1和form2中要添加哪些代码才能实现这个功能
最好有完整的代码,贴出来看看
...全文
101 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gw6328 2009-08-08
  • 打赏
  • 举报
回复
学习
fjtxwd 2009-08-08
  • 打赏
  • 举报
回复
谢谢除一楼以外的所有人
Skyhoo 2009-08-08
  • 打赏
  • 举报
回复
给你参考下吧


//FORM1
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(listBox1);
f2.ShowDialog();
}

//FORM2的

public partial class Form2 : Form
{
ListBox lb = new ListBox();
public Form2(ListBox lb)
{
this.lb = lb;
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
lb.Items.Add(textBox1.Text);
this.Close();
}


jiyuanyasou 2009-08-08
  • 打赏
  • 举报
回复
用全局变量的思想也可以实现,c#中没有,就顶一个静态类就行了
霜寒月冷 2009-08-08
  • 打赏
  • 举报
回复
属性
szzzp110 2009-08-08
  • 打赏
  • 举报
回复
定义个类,用get set
yijianxiangde100 2009-08-08
  • 打赏
  • 举报
回复
搞定了,给lz源码:
Form1源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WFTwoForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(this.listBox1);
form2.Show();
}
}
}


Form2源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WFTwoForm
{
public partial class Form2 : Form
{
private ListBox _listBox;
public Form2(ListBox listBox)
{
_listBox = listBox;
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this._listBox.Items.Add(this.textBox1.Text);
}
}
}

dancingbit 2009-08-08
  • 打赏
  • 举报
回复
基本上,这个用属性就可以实现。
给你个链接:
http://blog.csdn.net/Knight94/archive/2006/08/22/1104957.aspx
dongbangwu 2009-08-08
  • 打赏
  • 举报
回复
请别人帮忙需要客气一些,要有谦虚诚恳的态度

110,533

社区成员

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

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

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