skip to Main Content

When I was editing my project and tweaking it, I decided to test it, but it won’t run.
When I looked in the console, it closed with an exit code of 0.
Is it a Visual Studio bug? I’m on Visual Studio 2022, by the way.
If it is a code problem, here is the code on Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Flipbook
{
    public partial class Form1 : Form
    {
        Graphics g;
        Pen p;
        Brush b;
        bool d = false;
        int tool = 1;
        int width = 10;
        Point m1;
        Point m2;
        int selectedframe = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void undoInCurrentPageToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void redoInCurrentPageToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void cutCurrentPageToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            tool = 3;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tool = 1;
        }

        private void copyCurrentPageToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void pastePageToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void addPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            imageList1.Images.Add(Flipbook.Properties.Resources.blank);
        }

        private void deleteThisPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            imageList1.Images.RemoveAt(selectedframe);
        }

        private void flipToTheNextPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            selectedframe++;
            pictureBox1.Refresh();
            pictureBox1.Image = imageList1.Images[selectedframe];
        }

        private void flipToThePreviousPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!(selectedframe == 0))
            {
                selectedframe--;
                pictureBox1.Refresh();
                pictureBox1.Image = imageList1.Images[selectedframe];
            }
        }

        private void newAnimationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listView2.Items.Clear();
            listView2.Items.Add("", selectedframe);
            pictureBox1.Refresh();
            g = pictureBox1.CreateGraphics();
            p = new Pen(Color.Black, 1);
            b = new SolidBrush(Color.Black);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            d = true;
            m1 = e.Location;
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            d = false;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            m2 = e.Location;
            p.Color = panel2.BackColor;
            p.Width = width;
            b = new SolidBrush(panel2.BackColor);
            if (d)
            {
                switch (tool)
                {
                    case 1:
                        g.DrawLine(p, m1, m2);
                        break;
                    case 2:
                        g.FillEllipse(b, e.X, e.Y, width, width);
                        break;
                    case 3:
                        g.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, width, width);
                        break;
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            tool = 2;
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            width = (int)numericUpDown1.Value;
        }

        private void panel2_Click(object sender, EventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            if (cd.ShowDialog() == DialogResult.OK)
            {
                panel2.BackColor = cd.Color;
            }
        }
    }
}

Program Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Flipbook
{
    internal 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());
        }
    }
}

I tried to reload visual studio, tweak some settings, and I was expecting it to run normally, but the program immediately closed.

2

Answers


  1. My answer probably wont help you, since i cant imagine you changed some of that, but i still give it a shot.
    First, check your program.cs file, there should be a line

    Application.Run(new Form1());
    

    Check that there is indeed Form1 after new.

    Second, go to Project -> Properties, check if under Output Type stands Windows Application.

    Third thing, go to Project -> Configure Startup Project. Check if indeed the right project is selected as startup.

    Login or Signup to reply.
  2. It may not work if you have an antivirus because antiviruses may delete the content of your new projects. Try deactivating it and check if it put your project to quarantine if you use one

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search