我想使用openfiledialog()打开excel文件并在datagridview中显示它 我想在openfiledialog中按下打开时启动计时器 但是当文件完全加载到datagridview中时,计时器启动;
答案 0 :(得分:1)
@PaulF是对的,不需要 WndProc
尝试这个,
if(openFileDialog1.ShowDialog() == DialogResult.OK) {
if (!string.IsNullOrEmpty(openFileDialog1.FileName)) {
timer1.Start();
}
}
您可以按OpenFileDialog
抓取WndProc
窗口,这是一个示例
bool IsOpenFileDialog = false; // global variable to check if openfile opened
private void button1_Click_1(object sender, EventArgs e) {
IsOpenFileDialog = true; // button opens openfile dialog on click event
openFileDialog1.ShowDialog(); // show it, it waits until dialog closed
IsOpenFileDialog = false; // after closed set it to false
}
private void timer1_Tick(object sender, EventArgs e) {
textBox1.Text += "Ticking! \n"; // added a textbox to show the ticking
}
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == 289) // check message loop
{
if (!timer1.Enabled && IsOpenFileDialog) {
// if timer is not running already and button clicked to open openfiledialog
timer1.Start(); // start timer
}
}
}