6 Replies - 2225 Views - Last Post: 08 September 2012 - 01:39 PM Rate Topic: -----

#1 KyletheSeal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-September 12

I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 12:32 PM

I am new to c# and I can't get this code to work because of a error. I am using visual c# 2010. I'm also using windows 7. The code with the error is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

]
Error	1	The best overloaded method match for 'System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext)' has some invalid arguments	C:\Users\Radio Shack\AppData\Local\Temporary Projects\WindowsFormsApplication1\Program.cs	18	13	WindowsFormsApplication1


The 2 errors are: Error 2 Argument 1: cannot convert from
'WindowsFormsApplication1.Form1' to 'System.Windows.Forms.ApplicationContext'	C:\Users\Radio Shack\AppData\Local\Temporary Projects\WindowsFormsApplication1\Program.cs	18	29	WindowsFormsApplication1

This post has been edited by tlhIn`toq: 08 September 2012 - 01:09 PM
Reason for edit:: [code] your code here [/code] tags added


Is This A Good Question/Topic? 0
  • +

Replies To: I can't figure out how to fix these 2 errors

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5678
  • View blog
  • Posts: 12,213
  • Joined: 02-June 10

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:14 PM

let me guess... You changed the name of form1 but didn't change any of the references to it.




Excuse me?
C:\Users\Radio Shack

Are you trying to make a production release application? You're so not ready for that.

Its hard for us to tell what you screwed around with in the basic code that Visual Studio builds for you. Next time don't play with stuff you don't understand just to see what happens, because *this* is what happens - it breaks in a way that your or others don't know.

Its a basic WinForms application. Just start a new solution - and this time use meaningful names from the start. None of this "WindowsFormsApplication1" bull. If the project is supposed to be a calculator then name it 'WinFormsCalculator' for example.



My standard beginner resources post

First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover. Do a couple hundred on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.

Then later you can start architecting your own simple stuff. Build a calculator. Build a DVD library program. Etc. Stuff that doesn't involve the complexity of a game. Then move up to games.



There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 0
  • +
  • -

#3 KyletheSeal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-September 12

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:24 PM

C:\Users\Radio Shack
That is just the name of my user on this computer.
production release application?
The script I am trying to make is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public partial class Form1 : Form
{
    string[] text = {
         "Seals are awesome"
                    };
    PictureBox pb;
    Bitmap surface;
    Graphics device;
    Random rand;

    public Form1()
    {
        IntitializeComponent();
    }

    private void IntitializeComponent()
    {
        throw new NotImplementedException();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //intilize
        this.Text = "Text Drawing Demo";
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Size = new Size(600, 500);
        rand = new Random();

        //create grahpics device
        pb = new PictureBox();
        pb.Parent = this;
        pb.Dock = DockStyle.Fill;
        pb.BackColor = Color.Black;

        //create graphics device
        surface = new Bitmap(this.Size.Width, this.Size.Height);
        pb.Image = surface;
        device = Graphics.FromImage(surface);

        //make new font
        Font font = new Font("Times New Roman", 26, FontStyle.Regular, GraphicsUnit.Pixel);

        //draw the text
        for (int n = 0; n < text.Length; n++)
        {
            device.DrawString(text[n], font, Brushes.Red, 10, 10 + n * 28);
        }

        //refresh the drawing surface
        pb.Image = surface;
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        device.Dispose();
        surface.Dispose();
    }
}


The script that the error is in is from the format that was already in visual studio 2010 edition. I am using a book but it doesn't explain if i need to create my own format so I just went with one that was already in visual studio.

This post has been edited by tlhIn`toq: 08 September 2012 - 01:27 PM
Reason for edit:: Use proper code tags or I'm locking the thread

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5678
  • View blog
  • Posts: 12,213
  • Joined: 02-June 10

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:35 PM

We don't do scripts. C# is for building applications, not scripting.

As I said, I can't tell you what you played with to break the ready-made code Visual Studio provided.

You don't have much code there. Just start a new solution and you'll be fine. Be sure to start a Windows Forms Application project and not a blank project. You shouldn't be hand coding or even opening the Program.cs file at this point in your education.

You're obviously screwing with the VS generated stuff because IntializeComponent() does not throw an exception by default

All this stuff in your Form1_Load... Does not belong there. It should be in the Form1.Designer.cs file.

To put it bluntly: WTF are you doing? Step by step with screen captures.

Quote

12 "Seals are awesome"


Yes. Especially the baby ones, grilled over mesquite wood chips.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:37 PM

Your code in post #3 is not declared within a namespace. So your code in post #1 cannot find a Form1() that can be instantiated and passed in to Application.Run().

C# code is usually called "code", not "scripts".
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5678
  • View blog
  • Posts: 12,213
  • Joined: 02-June 10

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:37 PM

Listen carefully... We are not going to keep editing your posts. Use the code tags like everyone else.

Paste our code in from VS.
Select all your code
Click the CODE button in the editor. It will wrap your code with tags.
:code:
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: I can't figure out how to fix these 2 errors

Posted 08 September 2012 - 01:39 PM

You mentioned in post #3 that you are using a book. What's the title of the book and who is the author?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1