Malek
Malek

Reputation: 1329

Windows Form is Really Laggy

I have a windows Form Project that runs smoothly and fine on framework 4.5.1 But yet I have a project on framework 2.0 that is so laggy even after i changed the target framework to 4.5.1

so why is one project slow and the other is normal?

Update :

here is the Main From

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

namespace DataBaseLab_Library_Project
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

    private void button5_Click(object sender, EventArgs e)
    {
        System.Windows.Forms.Application.Exit();
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button4_Click(object sender, EventArgs e)
    {
        MessageBox.Show(" ", "About US");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.Close();

        Add AddForm = new Add();
        AddForm.Show();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
        Search SearchForm = new Search();
        SearchForm.Show();
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {

    }
}
}

and here is its design

enter image description here

Update 2 :

Form "Add.cs" that dose not lag .

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

namespace DataBaseLab_Library_Project
{
    public partial class Add : Form
    {
        public Add()
        {
            InitializeComponent();
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            AddBook AddBookForm = new AddBook();
            AddBookForm.Show();


        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
            MainForm mainForm = new MainForm();
            mainForm.Show();

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void publisherButt_Click(object sender, EventArgs e)
        {
            this.Close();
            AddPublishercs AddPublisherForm = new AddPublishercs();
            AddPublisherForm.Show();
        }

        private void authorButt_Click(object sender, EventArgs e)
        {
            //this.Close();
            //AddAuthor AddAuthorForm = new AddAuthor();
            //AddAuthorForm.Show();
        }

        private void Add_Load(object sender, EventArgs e)
        {

        }
    }
}

Upvotes: 0

Views: 2619

Answers (1)

Matt
Matt

Reputation: 3680

Try removing the panel1 paint eventhandler. This will get called (even tho its empty) ever time the panel has to draw itself, which is all the time in a designer environment.

Remove this code:

 private void panel1_Paint(object sender, PaintEventArgs e)
    {

    }

There will also be code inside of InitializeComponent() similar to this

this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1);

Remove it as well. Clean and rebuild solution. Close all designer windows. Try again.

Upvotes: 1

Related Questions