C#, WPF - OpenFileDialog does not appear

前端 未结 7 653
温柔的废话
温柔的废话 2020-12-09 20:54

I have been searching up and down the web and unfortunately never came across an issue quite like mine, so here goes:

My C# WPF application won\'t show me no OpenFil

7条回答
  •  感情败类
    2020-12-09 21:29

    sometime [staThread] not working, you can try this:

        public void showOpenFileDialog()
        {
            OpenFileDialog im = new OpenFileDialog();
            if (im.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = im.FileName;
            }
        }
    
    
        private void select_button_Click(object sender, EventArgs e)
        {
            Thread newThread = new Thread(new ThreadStart(showOpenFileDialog));
            newThread.SetApartmentState(ApartmentState.STA);
            newThread.Start();
        }
    

提交回复
热议问题