我希望有人能帮助我。我比较新,想了解如何将一个类中的变量值传递给另一个类。在这种情况下,我想在 Button_Click_2 中使用 Button_Click_1 中的 numPage 和 filePath 数组。
先感谢您!
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog1 = new Microsoft.Win32.OpenFileDialog();
openFileDialog1.Filter = "Images (.jpg)|*.jpg";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
bool? userClickedOK = openFileDialog1.ShowDialog();
if (userClickedOK == true)
{
string[] filePaths = openFileDialog1.FileNames;
int imageNum = 0;
lblFilePath.Content = filePaths[imageNum];
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
imageNum++;
lblFilePath.Content = filePath[imageNum];
}
}