开发者

Get data from console to form c# help? very small app

I'm trying to convert a console app to a form I got the form part showing up correctly working but can't figure out how to make the program get its data from the form instead of the console any suggestions?

Console Application

namespace doomsday
{
    public class doomsday
    {


       private string firstName;

        public string GetName()
        {
            return this.firstName;
        }//end method GetName

    public doomsday()
    {
       Console.Write(" what is your first name: ");
       this.firstName = Console.ReadLine();


    }// end default constructor

    public string DisplayGreeting()
    {
        return "Hello, " + this.GetName();
    }
    static void Main()
    {
        Application.EnableVisualStyles();

        doomsday hello = new dooms开发者_如何学编程day();

        Console.WriteLine(hello.DisplayGreeting());

        Console.ReadLine();

       Application.Run(new Form1());


    }

Form Application

namespace doomsday
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();


        }


    }
}

Form http://img251.imageshack.us/img251/6995/capturembq.jpg


In the Visual Studio form designer, add a button to your form. Double-click the button to add an event handler for the button's Click event. Inside the body of this new method you can access the Text property of the text box. For example:

private void button1_Click(object sender, EventArgs e)
{
    string name = textBox1.Text;
    textBox2.Text = "Hello, " + name;
}


Change private string firstName;

to

public string firstName;



namespace doomsday
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();


        }
       public void whenTextbox1LoseFocus {
            var greet = new doomsday();
            greet.firstname = textBox1.Text;
            textbox2.text = greet.DisplayGreeting()
        }

    }
}


I am not sure wether i get you on this, but if you want to pass the entries from the console to the form you need to have a public property on the form.

    Form1 form = new Form1();
    form.theDay = doomsday;
    Application.Run(form); 

On the Form1 just offer a Property like this:

public doomsday theDay { get; set; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜