本文介绍了如何以另一种形式显示结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是c#编码的新手。我想知道如何将字符串str1的值传递给另一个表单,并从下面的代码中以另一种窗体形式显示它。好吧,我可以在消息框中显示为MessageBox.Show(str1);但是我想传递str1的值并以另一种形式显示它。



我尝试了什么:



使用System; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.IO;
使用System.Linq;使用System.Reflection
;
使用System.Text;
使用System.Threading.Tasks;
使用System.Runtime.InteropServices;
使用MyExcel = Microsoft.Office.Interop.Excel;
使用System.Windows.Forms;
使用静态System.Windows.Forms.VisualStyles.VisualStyleElement;
使用Microsoft.Vbe.Interop;
使用System.Diagnostics;


名称空间贷款
{

公共部分类Form1:表格
{
public Form1()
{

InitializeComponent();
}

private void button1_Click(object sender,EventArgs e)
{




OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title =选择一个Excel文件;
fdlg.InitialDirectory = @d:\ test;
fdlg.Filter =所有文件(*。*)| *。* |所有文件(*。*)| *。*;
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;





if(fdlg.ShowDialog()== DialogResult.OK)
{
MessageBox.Show( 所选文件是:+ fdlg.FileName);

}

MyExcel.Application xlApp;
MyExcel.Workbook xlWorkBook;
MyExcel.Worksheet xlWorkSheet;
MyExcel.Range范围;

string cellValue;
int rCnt;
int cCnt;
int rw = 0;
int cl = 0;

Loans.Form2 frm = new Loans.Form2();


xlApp = new MyExcel.Application();
xlWorkBook = xlApp.Workbooks.Open(@ fdlg.FileName,0,true,5,,,true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,\ t,false ,false,0,true,1,0);
xlWorkSheet =(MyExcel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

range = xlWorkSheet.UsedRange;
rw = range.Rows.Count;
cl = range.Columns.Count;

//MessageBox.Show(Working);
for(rCnt = 1; rCnt< = rw; rCnt ++)
{
for(cCnt = 1; cCnt< = cl; cCnt ++)
{

string str = Convert.ToString((range.Cells [rCnt,N]为MyExcel.Range).Value2);

if(str ==3|| str ==4|| str ==5|| str ==6|| str ==7)
{
string str1 = Convert.ToString((range.Cells [rCnt,cCnt] as MyExcel.Range).Value2);
MessageBox.Show(str1); //想要以单独的形式显示str1的值
//


}


}
}



xlWorkBook.Close(true,null,null);
xlApp.Quit();

Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);

}

public void显示(字符串文本)
{

this.Show();
}




private void Form1_Load(object sender,EventArgs e)
{
InitializeComponent();
}


}
}
解决方案


这篇关于如何以另一种形式显示结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 12:00