Results 1 to 8 of 8

Thread: C# Help

  1. #1
    Join Date
    Apr 2010
    Location
    Rogers, Arkansas
    Posts
    13
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Exclamation C# Help

    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 Code:
    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}."userNameuserAge);
                
                
    // 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);
            }
        }

    If anyone can help that would be great =D

  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  3. #3
    Join Date
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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...
    Last edited by XcanadamanX; 04-06-2010 at 02:31 PM.

  4. #4
    Join Date
    Sep 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  5. #5
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

  6. #6
    Join Date
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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

  7. #7
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by XcanadamanX View Post
    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:
    Code:
    using System.Windows.Forms;
    
    ...
    
    MessageBox.Show("Hello World");

  8. #8
    Join Date
    Apr 2010
    Location
    Rogers, Arkansas
    Posts
    13
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thx for the help compiled fine =D wooohooo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •