Author Topic: OpenFileDialog  (Read 824 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
OpenFileDialog
« on: 2012-02-16, 06:28:36 PM »
 
Code: [Select]
 private void OpenNewSeq(object sender, System.EventArgs e)
 {
   Stream myStream = null;
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    openFileDialog1.InitialDirectory = "c:\\" ;
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
    openFileDialog1.FilterIndex = 2 ;
    openFileDialog1.RestoreDirectory = true ;
    
    openFileDialog1.ShowDialog();
    //openFileDialog1.Dispose(); Commented out, it doesn't affect the results anyways.
 }

Within GameForm.cs

 I'm calling this method with an Event Handler, when my game is run, I go to File > Open, and when Open is clicked, it runs this function.

The only problem is that the window freezes. Is there somewthing I'm doing wrong?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2752
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: OpenFileDialog
« Reply #1 on: 2012-02-17, 06:21:28 AM »
This one had me stumped for a few minutes.  I had to run the project in the C# IDE.  And for some reason when I did that I got an error instead of a freeze that explained what needed to be done: you need to add [STAThread()] above the Main function in Project.cs.

So:
1. Open Project.cs
2. Find public static void Main()
3. Make it look like this:

Code: [Select]
   [STAThread()]
   public static void Main()
   {
      try
      {
         GameDisplayMode mode = (GameDisplayMode)System.Enum.Parse(typeof(GameDisplayMode), m_res.GetString("_DisplayMode"));
         ...

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: OpenFileDialog
« Reply #2 on: 2012-02-17, 09:16:04 AM »
Merci, works like a charm. I can use this for the Open and SaveFile Dialogs.