C# Help

Started by G_G, September 15, 2009, 12:18:13 am

Previous topic - Next topic

winkio

September 16, 2009, 01:05:14 am #20 Last Edit: September 16, 2009, 01:09:41 am by winkio
Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 1
Okay so I want to be able to have bookmarks. So you can add things to a menu strip by doing this.

menuStrip1.Items.Add("Fruit");


Okay so here's my idea, I wanted to save all bookmarks in a file which I figured out how to do. Now my question is pretty much like the one with visual basic. So this is what I want to do.

# below is the text containing all bookmarks just for example
text = [bookm1, bookm2, bookm3]
# okay so thats three bookmarks
for i in 0...text.size
 menuStrip1.Items.Add(i.tostring);
end


If that made any sense at all...Anyways I want it like that if anyone can help please that'd be great.

a few points:
use // instead of # for comments
C# uses real arrays, not the floating amorphic stuff of RGSS.  Learn how they work, or else you are screwed.
semicolons
for loops
braces { } instead of ends

// below is the text containing all bookmarks just for example
string[] text = {"bookm1", "bookm2", "bookm3"};
// okay so thats three bookmarks
for (int i = 0; i < text.Length; i++)
{
    menuStrip1.Items.Add(text[i]);
}

(for all those coders out there, I know I could have used an extended for loop, but I think he should know the regular ones first.)
Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 2
Okay when my browser is done I'm going to make a help file for it. So this is kind of two questions.
How would I open this helpfile? I have a top tool bar that has a Help button on it so I want that to open the help file.
Next how would I just open this helpfile by pressing F1 or something?

you are going to need to add a keyboard event listener, then make an onKeyboardEvent method.  But you have no idea how interfaces and stuff work, so good luck.  I'd ask when you get there.

Quote from: game_guy on September 15, 2009, 12:18:13 am
Question 3

Next okay so how would I go replacing all the spaces in a line of text? Like the url says this

you tube.com

How would I replace that space with nothing or with a different letter/symbol? Something like this in ruby.

name = "Alu x es"
name.delete!(" ")

that would delete all the spaces but not only do I want to do that I want to be able to replace that space with a letter or symbol. Is is possible and if so how?

There is an easier way with regex, but I don't know if you will be ready for it, so I'll give you a method that splits and recombines:
string s = "Al u xes";
           // replace the ' ' with whatever character to split at.  It's an array, so you can split at any number of characters.
           char[] delim = { ' ' };
           string[] ssplit = s.Split(delim);
           string snew = ssplit[0];
           for (int i = 1; i < ssplit.Length; i++)
           {
              //replace the '-' with whatever you want to replace the space
               snew += "-";
               snew += ssplit[i];
           }

at the end, snew has the new string, which in this case, is Al-u-xes.

Blizzard

September 16, 2009, 05:30:06 am #21 Last Edit: September 16, 2009, 05:38:05 am by Blizzard
1. Let's say you have an array or list of strings.

foreach (string bookmark in array)
{
   menuStrip1.Items.Add(bookmark);
}


Or winkio's alternative using an index iterator. Or even this:

menuStrip1.Items.AddRange(array);


2. If I remember right, you can embed a chm file which you generated beforehand using HMTL Workshop or some other HTML compiler. Look it up on the internet, it's very easy.
If you add the help file call to an option in the menu strip, you can bind F1 as hotkey over the "Properties" window. Then simply double click on the option in the menu to generate a click event in which you put in the code to call the help file.

3.
string = string.Replace(" ", ""); // replaces spaces with empty strings
string = string.Replace(" ", "-"); // replaces spaces with dashes


I'm not 100% sure if it was "Replace" or some other method, but you shouldn't have no problems finding the right one with Intellisense.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

right, Blizz has experience, while I picked up C# 2 weeks ago.  :^_^':

G_G

thanks guys for your help :) *lvs up*

Blizzard

Oh, don't worry about it, winkio. :) You'll learn quickly how fast you can do some things in C#. It didn't take me long to learn some of the nice features the object model of .NET supports. :D

We made an embedded help file in a college course so I still kinda remember how we did it. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

winkio

yeah for the intro to computer game creation course, we are building our final project in C# using XNA libraries (thus why our textbook is an xbox 360 controller :P)

I don't think I've ever touched .NET...

Blizzard

One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

@#3: You'll want to use a Regex to replace spaces after the original domain with %20 and just delete the rest.

G_G

September 16, 2009, 06:48:22 pm #28 Last Edit: September 16, 2009, 06:56:21 pm by game_guy
okay another question...well problem when I click a link that normally opens a new tab or window it opens up internet explorer instead and same thing with downloads...anyway to fix this?

EDIT:
How do we open another form up?

Blizzard

Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: Blizzard on September 17, 2009, 02:14:03 am
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.


Its apparently an error when I use the
childForm.MdiParent = this;

It wont work this is the error
Form that was specified to be the MdiParent for this form is not an MdiContainer.
Parameter name: value


This is my code
Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();

fugibo

Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.

Blizzard

Quote from: game_guy on September 25, 2009, 08:30:59 pm
Quote from: Blizzard on September 17, 2009, 02:14:03 am
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Show();


Form can be any class that inherits Form you have defined in your namespace or, of course, from another namespace.

As for the problem with downloads, IDK. It might be that you need to set your browser as default browser. I have no idea how to do this. It's probably a registry thing.


Its apparently an error when I use the
childForm.MdiParent = this;

It wont work this is the error
Form that was specified to be the MdiParent for this form is not an MdiContainer.
Parameter name: value


This is my code
Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();



The parent window probably isn't an MDI container. :P Either leave that line out or make the parent window an MDI container. It should be one of the window properties.

Quote from: Longfellow on September 26, 2009, 08:56:08 am
Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.


Don't be affected by your Max bias. It's not as slow as you think.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

I tried that and it worked. But it displayed the window behind everything in the parent window.. The background of the first form was grey when I changed it, then I tested it and form2 displayed in the grey but behind everything else

Also say I want to create a module method like this.
module Config
  def self.write_text(file, text)
    # stuff here
  end
end


I want to create a method in a seperate thing where I can just call it like this
Text.write_text("Test.txt", "Test")


So exactly what do I do to go doing that? I know its not going to be the same as rgss but I'm trying to explain it in rgss is all.

Blizzard

You should probably use the intended MDI container "class" then. xD

There are classes and methods for file access like File and File.Open. Just use the Intellisense. It will guide you through what you need to use. Just read what the methods and parameters do.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Well I know how to do the file open and stuff but I want a method that I can just call that writes text to the file so I dont have to keep typing the same thing over and over. If I have to I will.

Blizzard

FileStream.write(STRING)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

September 27, 2009, 03:46:08 pm #37 Last Edit: September 27, 2009, 03:47:26 pm by Longfellow
Quote from: Blizzard on September 27, 2009, 01:53:17 pm
Quote from: Longfellow on September 26, 2009, 08:56:08 am
Quote from: Blizzard on September 16, 2009, 12:48:45 pm
One of the greatest things about C# is that it's running actually on a native platform when on XBox / XBox 360. <3


The downside is that it's running on a non-native, superfluous VM on every other platform.


Don't be affected by your Max bias. It's not as slow as you think.


For the record, Objective-C isn't "fast" either - it's almost as dynamic as Ruby, which means it's also much slower than C/C++. My main complaint with C# is that on Windows, there's no need for a VM, so that's just slowing it down and sucking battery life for no reason, and on other platforms like Zune/WinMobile, a VM is just overkill (my only complaint with Android is that it uses a VM, too). This isn't Java, where you're compiling for every platform you can, this is (for all intents and purposes) a Microsoft-only product with all the limitations of a cross-platform product. If C# took the Obj-C route and just ran off a dynamic runtime, it'd be awesome, but right now it's ridiculous.

(Edit: This is pretty ironic, given that it's coming from a guy who considered writing an IDE in pure Ruby a year ago :P)

Blizzard

I agree, C# VM just for Windows isn't needed. But C# wasn't supposed to be Windows only. It's just that Unix users don't want to have a good and versatile language such as C# for Unix because of their childish and usually just Unix-fanboy based hatred for Microsoft. Mono never went beyond .NET 1.0 which is quite a shame especially since .NET 2.0 is MUCH better than 1.0. Blame the fanboys, it's their fault.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on September 27, 2009, 03:51:40 pm
I agree, C# VM just for Windows isn't needed. But C# wasn't supposed to be Windows only. It's just that Unix users don't want to have a good and versatile language such as C# for Unix because of their childish and usually just Unix-fanboy based hatred for Microsoft. Mono never went beyond .NET 1.0 which is quite a shame especially since .NET 2.0 is MUCH better than 1.0. Blame the fanboys, it's their fault.


Uh, Mono is still under development, and I'm pretty sure it's nearly 2.0 if it's not already. 0_o A lot of people are using it, too - it's just that a lot still prefer Gtk/Python or Qt, and don't really have any need for Mono yet.

And then there's the fact that they're always gonna be two steps behind Microsoft, simply because it's an Open Source project following a closed-source, proprietary project.