Need Some Help (again)

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
Andrew_b




Socialist

Posts: 4188
Joined: Sat Feb 24, 2007 4:52 pm
Contact:

Need Some Help (again)

Post by Andrew_b »

First off: I am using C#.

Im trying to get my open button to open but the browser never shows up. I just started today. Also if anyone could help me, i think it would be useful if i could get it to open on a certain directory all the time.

My Code:

Code: Select all

private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog;
        }
It currently does not compile my app cause of some errors. but when it does compile it wont show the browser.

Thanks
-Andrew_b
Last edited by Andrew_b on Sat Feb 02, 2008 5:54 pm, edited 1 time in total.
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

if you want to open a file, why are you using a folder browser dialog?
i just started C# yesterday but it should be something like this

Code: Select all

private void openToolStripMenuItem_Click(object sender, EventArgs e) 
{
string path;
OpenFileDialog ofd = new OpenFileDialog;
ofd.InitialDirectory = <directory> //put you directory there
if (ofd.ShowDialog() != DialogResult.Cancel)
{
path = ofd.FileName;
}
}
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

All that you did in your code was start to declare a variable.

Here's what you need to do

Code: Select all

FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() != DialogResult.Cancel)
{
 // do whatever you want on a successfull dialog(user didn't press X or cancel)
}
I'll split up something most programmers do in one step into two steps to hopefully give you an idea of what's going on.

When you say

Code: Select all

FolderBrowserDialog fbd;
it just creates a variable with nothing in it(null)
when you say

Code: Select all

fbd = new FolderBrowserDialog();
it creates a new object of FolderBrowserDialog and puts the pointer to where it is in memory into your fbd variable.

This was done in one step in the example I gave.

when you run the ShowDialog method, it returns a DialogResult
The way I gave is the way I usually do it, but you can store the result in a variable if you want

Code: Select all

DialogResult dr = fbd.ShowDialog();
Then you could perform more than one if statement on it, or use a switch.
User avatar
Andrew_b




Socialist

Posts: 4188
Joined: Sat Feb 24, 2007 4:52 pm
Contact:

Post by Andrew_b »

Ok i have everything working great now. it opens txts and shows the text inside of them.

Now what do i use (in C#) to make my menu button 'About' Open a new window that shows what the program is about?
User avatar
Anthony




Translator Connoisseur New Age ONI

Posts: 1001
Joined: Thu Jul 06, 2006 10:19 pm
Location: Whittier, CA
Contact:

Post by Anthony »

Create an about form

then do

Code: Select all

new About().ShowDialog();
User avatar
Andrew_b




Socialist

Posts: 4188
Joined: Sat Feb 24, 2007 4:52 pm
Contact:

Post by Andrew_b »

Thanks everyone.

How would i close a text file? I tried TextBox1.Text(""); but that just erases the text.

How would i close a file?
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post by Prey »

You can't close a file.. but you can close whatever you opened the file with. For example if you used a StreamReader, you would just call its Close() method.
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Post Reply