SRL Archive - C/C++ Help and Tutorials

C# Help


Syronix

2010-04-06 02:55:01

I'm not sure if I can post this here but I figured it was worth a try. I just started learning C#
and was wondering if anyone could help me with this latest console project I am working on
I'm stuck on Line 58 because I can't figure out how to reference <System.Windows.Forms.dll>
Here's my code
[PHP]using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace BasicIO
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Basic Console I/O *****");
GetUserData();
FormatNumericalData();
Console.ReadLine();
}
static void GetUserData()
{
// Get name and age.
Console.Write("Please enter your name: ");
string userName = Console.ReadLine();
Console.Write("Please enter your age: ");
string userAge = Console.ReadLine();

// Change echo color, just for fun.
ConsoleColor prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;

// Echo to the console.
Console.WriteLine("Hello {0}! You are {1}.", userName, userAge);

// Restore previous color.
Console.ForegroundColor = prevColor;
}
// now we make use of some format tags.
static void FormatNumericalData()
{
Console.WriteLine("The value 99999 in various formats:");
Console.WriteLine("c format: {O:c}", 99999);
Console.WriteLine("d9 Format: {O:d9}", 99999);
Console.WriteLine("f3 format: {O:f3}", 99999);
Console.WriteLine("n format: {O:n}", 99999);

// Notice that upper- or lowercasing for hex
// determines if letter are upper- or lowercase.
Console.WriteLine("E format: {O:E}", 99999);
Console.WriteLine("e format: {O:e}", 99999);
Console.WriteLine("X format: {O:X}", 99999);
Console.WriteLine("x format: {O:x}", 99999);
}
void DisplayMessage()
{
// Using string.Format() to format a string literal.
string userMessage = string.Format("100000 in hex is {O:x}", 100000);

// You would need to reference System.Windows.Forms.dll
// in order to compile this line of code!
System.Windows.Forms.MessageBox.Show(userMessage);
}
}
}[/PHP]
If anyone can help that would be great =D

i luffs yeww

2010-04-06 09:43:16

using System.Windows.Forms(.dll)? I don't know too much about C*, but why not add that? :p

XcanadamanX

2010-04-06 10:10:16

When i was using C# last semester we just called messagebox.show('blah'). but we didnt use console apps. try putting using System.Windows.Forms at the top with just messagebox.show

e: ok i just downloaded C# again and it seems that the console applications can not use System.Windows.Forms…

fronty

2010-04-06 12:33:14

Project -> Add Reference or do it via Solution explorer.

TRiLeZ

2010-04-06 16:00:05


using System.Windows.Forms;

...

MessageBox.Show(userMessage);

XcanadamanX

2010-04-06 18:50:19

Trilez: did you try that in a console application? because when i tried this morning, it gave me errors

P.S: it says you're a Senior SRL Meember :P

TRiLeZ

2010-04-06 20:02:34

From: XcanadamanX
P.S: it says you're a Senior SRL Meember :P


LOL, I wonder who changed that…

To solve the problem:

Project > Add Reference > .NET > System.Windows.Forms > OK

Then:

using System.Windows.Forms;

...

MessageBox.Show("Hello World");

Syronix

2010-04-07 00:15:59

Thx for the help compiled fine =D wooohooo