如何訪問foreach
循環中的變量name
以及下面的try
?我需要在我的Main類中引用它。對不起,這是一個愚蠢的問題。從類內深處訪問變量
public class DragDropRichTextBox : RichTextBox
{
public DragDropRichTextBox()
{
//Enables drag and drop on this class.
this.AllowDrop = true;
this.DragDrop += DragDropRichTextBox_DragDrop;
}
public void DragDropRichTextBox_DragDrop(object sender, DragEventArgs e)
{
string[] _fileText;
_fileText = e.Data.GetData(DataFormats.FileDrop) as string[];
if (_fileText != null)
{
foreach (string name in _fileText)
{
try
{
this.AppendText(BinaryFile.ReadString(name));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
這裏就是我需要從我的主類調用它(請參閱 「HERE」 下面):
private void button5_Click(object sender, EventArgs e)
{
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, HERE);
}
}
}
目前還不清楚你的第一堂課和你的主課是如何相互關聯的。你在一個循環中有'name',你可以有多個值,那麼你是否要求所有的值,第一個值,最後一個值?需要更多信息。 – 2015-02-11 17:53:11