gpt4 book ai didi

c# - 将以一种形式输入的数据显示到另一种形式

转载 作者:行者123 更新时间:2023-11-30 15:35:19 25 4
gpt4 key购买 nike

我想要另一种形式将所选项目从一种形式的列表框中显示到另一种形式的富文本框,该文本框在单击按钮时打开。我在表单 1 中使用了以下代码片段来显示消息框中的内容,但现在我想要另一种形式。需要帮助...

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 cities
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{



StringBuilder message = new StringBuilder();

foreach (object selectedItem in listBox1.SelectedItems)
{
message.Append(selectedItem.ToString() + Environment.NewLine);
}
MessageBox.Show("You selected: \n" +message.ToString());


}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}

}
}

最佳答案

我使用下面的代码来实现我想要的。它做得很好! :)

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 cities
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{



StringBuilder message = new StringBuilder();


foreach (object selectedItem in listBox1.SelectedItems)
{
message.Append(selectedItem.ToString() + Environment.NewLine);
}
MessageBox.Show("Your Selected Cities :\n" + message.ToString() + "\n");

Form2 childForm = new Form2();
childForm.Controls["richTextBox1"].Text = message.ToString();
childForm.Show();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}

}
}

关于c# - 将以一种形式输入的数据显示到另一种形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com