Home c# How to invoke a form in C #?

How to invoke a form in C #?

Author

Date

Category

Hello everyone.

I wrote ftp, created a form, made buttons, assigned functions by buttons. At first there was no main, added main, now I don’t know how to call the form from the main.

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");
        }
    }
}

Answer 1, authority 100%

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 ();
}
}


Answer 2, authority 50%

static void Main () is not needed in forms.

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

static void Main ()

{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault (false);
Application.Run (new & lt; Name of your form & gt; ());
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions