# Making GUI's in C#



## Crockeo (Apr 17, 2010)

Hello the programmers at Tech Support Forum. This time I'm back with learning C#. I've learned most of C# quite quickly, probably because I know some of Java and a lot of C++, but I have a problem with making the GUI's.

(I'm using Visual C#)

Some of my problems are:

1) How do I switch between forms (or open other forms)

2) How do I close Forms

3) I have no idea yet, but I'll probably have more questions later


----------



## Ninjaboi (Dec 27, 2010)

Visual C# .NET: Creating Multiple Forms

That link tells you how to create a new form/multiple forms. As for closing your forms, you should just be able to select a form, right click, and go down to 'close'. If your talking about closing it from an event triggered in the program, try looking at this:

How can I close a form in Visual C# when I click a button for another form to open? - Yahoo! Answers


----------



## Crockeo (Apr 17, 2010)

Thank you Ninjaboi, you've helped me once again in my never ending quest to learn C#. I'll come back to this thread if I need any more help.


----------



## Crockeo (Apr 17, 2010)

I told you I'd be back, didn't I? Well, anyway, I was wondering how I would open an 'openfiledialog' and then retrieve the location from which file you open.

Thank you again whoever answers this, and thank you again Ninjaboi.


----------



## Ninjaboi (Dec 27, 2010)

How to Open File Dialog in C#

The code in that link sums it up in a nutshell. You might also be interested in some more details to the method you use.

OpenFileDialog Class (System.Windows.Forms)

Opening Files Using the OpenFileDialog Component

OpenFileDialog.OpenFile Method (System.Windows.Forms)


```
private void btnOpenTextFile_Click(object sender, EventArgs  e)
 {
 //First, declare a variable to hold the user’s file  selection.
 private void String input = string.Empty; 
  
 //Create a new instance of the OpenFileDialog because it's  an object. 
 private voidOpenFileDialog dialog = new OpenFileDialog();  
  
 //Now set the file type 
 dialog.Filter = "txt files (*.txt)|*.txt|All files  (*.*)|*.*"; 
  
 //Set the starting directory and the title. 
 dialog.InitialDirectory = "C:"; dialog.Title = "Select a  text file"; 
  
 //Present to the user. 
 if (dialog.ShowDialog() == DialogResult.OK)
      strFileName = dialog.FileName;
 if (strFileName == String.Empty)
      return;//user didn't select a file
 }
```

That's the code that was provided in the first link I mentioned. You should take a look at it and see how it was done.


Also, no problem. I'm just glad someones asking about C-style programming :grin:.


----------

