Hello to all.

I wrote ftp, created a form, made buttons, prescribed functions using buttons. At first it was without main, added main, now I don’t know how to call the form from the mine.

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; using FTP_lib; namespace Project1 { static void Main() { } public partial class Form1: Form { ftp_Manager newFtpManager = new ftp_Manager(); public Form1() { InitializeComponent(); } private void username_txtb_TextChanged(object sender, EventArgs e) { } private void Form1_Load_1(object sender, EventArgs e) { newFtpManager.ftp_Username = username_txtb.Text; newFtpManager.ftp_Password = password_txtb.Text; } private void getContent_Click(object sender, EventArgs e) { newFtpManager.getContent("ftp://youdomain.com"); } private void upload_file_Click(object sender, EventArgs e) { newFtpManager.UploadFile("ftp://yourdomain.com/filedestination", "C:\\myfile.exe"); } private void donwload_button_Click(object sender, EventArgs e) { newFtpManager.DownloadFile("ftp://ftp.mama.tomsk.ru/festival/", "C:\\Download"); } private void delete_file_Click(object sender, EventArgs e) { newFtpManager.DeleteFile("ftp://yourdomain.com/file.exe"); } } } 


    2 answers 2

    Create an instance of this form.

     Form1 example = new Form1(); example.Show(); 

    Added from comment.

    Main try to change as little as possible. When you need to call the desired form, use the AddWindow method:

     public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void AddWindow() { Form2 examp = new Form2(); examp.Show(); } } 
    • Like this? Nothing happens ... public partial class Form1: Form {static void Main () {Form1 example = new Form1 (); example.Show (); } ftp_Manager newFtpManager = new ftp_Manager (); public Form1 () - marioxxx
    • Moved in response. - Chistyakov Vladislav
    • public partial class Form1: Form {static void Main () {AddWindow (); } - marioxxx
    • Swears Error 1 An object reference field for a non-static field, method, or property - marioxxx
    • and everything works, during the creation it was necessary to specify the windows form, and I indicated as a console application - marioxxx

    in forms static void Main () is not needed.

    and in the file (by default) program.cs should be lines

    static void Main ()

      { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new <Название вашей формы>()); } 
    • thanks, but already figured out) - marioxxx