开发者

Problem with some auto-refresh that happens on a button when mousehover

开发者 https://www.devze.com 2022-12-28 06:03 出处:网络
I\'ve been working on a windows application lately. It\'s build up from several classes that basically draw an image together. After that was done, I made 2 buttons with an event on click that changed

I've been working on a windows application lately. It's build up from several classes that basically draw an image together. After that was done, I made 2 buttons with an event on click that changed a few colors of the drawn objects.

Everything works fine including the buttons, but my problem is that each time I hover over the buttons with my mouse the form seems to refresh (it flashes once). Naturally I only want the form to refresh after clicking the button, not on hover.

I hope I'm clear on explaining my issue.

I'm not sure what piece of code to give you. But here is my main application form:

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;

namespace Kruispunt
{
    public partial class Kruispunt : Form
    {
        private Oversteekplaats autoNZ, autoOW, fietsNZ, fietsOW, zebraNZ, zebraOW;

        private Oversteekplaats[] oversteekplaatsen = new Oversteekplaats[6];

        private CPU cpu = new CPU();

        private Button NZknop = new Button();
        private Button OWknop = new Button();

        private CheckBox storingCheckBox = new CheckBox();

        public Kruispunt()
        {
            InitializeComponent();

            Graphics g = Graphics.FromHwnd(this.Handle);

            autoNZ = new Oversteekplaats(300, 300, 200, 200, g, Status.Aan, Color.Green, Orientatie.NZ, Soort.Auto);
            autoOW = new Oversteekplaats(300, 300, 200, 200, g, Status.Aan, Color.Red, Orientatie.OW, Soort.Auto);

            fietsNZ = new Oversteekplaats(300, 120, 500, 200, g, Status.Aan, Color.Green, Orientatie.NZ, Soort.Fiets);
            fietsOW = new Ove开发者_C百科rsteekplaats(120, 300, 200, 500, g, Status.Aan, Color.Red, Orientatie.OW, Soort.Fiets);

            zebraNZ = new Oversteekplaats(300, 120, 620, 200, g, Status.Aan, Color.Green, Orientatie.NZ, Soort.Voetganger);
            zebraOW = new Oversteekplaats(120, 300, 200, 620, g, Status.Aan, Color.Red, Orientatie.OW, Soort.Voetganger);

            oversteekplaatsen[0] = autoNZ;
            oversteekplaatsen[1] = autoOW;
            oversteekplaatsen[2] = fietsNZ;
            oversteekplaatsen[3] = fietsOW;
            oversteekplaatsen[4] = zebraNZ;
            oversteekplaatsen[5] = zebraOW;

            storingCheckBox.Text = "Kruispunt in storing";
            storingCheckBox.Location = new Point(20, 15);
            storingCheckBox.Size = new System.Drawing.Size(150, 25);
            this.Controls.Add(storingCheckBox);

            NZknop.Text = "Noord-Zuid Groen";
            NZknop.Location = new Point(20, 40);
            NZknop.Size = new System.Drawing.Size(110, 25);
            NZknop.Click += new EventHandler(NZknop_Click);
            this.Controls.Add(NZknop);

            OWknop.Text = "Oost-West Groen";
            OWknop.Location = new Point(20, 70);
            OWknop.Size = new System.Drawing.Size(110, 25);
            OWknop.Click += new EventHandler(OWknop_Click);
            this.Controls.Add(OWknop);
        }

        void NZknop_Click(object sender, EventArgs e)
        {
            cpu.groenNoordZuid(ref oversteekplaatsen);

            this.Refresh();
        }

        void OWknop_Click(object sender, EventArgs e)
        {
            cpu.groenOostWest(ref oversteekplaatsen);

            this.Refresh();
        }

        private void Kruispunt_Paint(object sender, PaintEventArgs e)
        {
            autoNZ = oversteekplaatsen[0];
            autoOW = oversteekplaatsen[1];
            fietsNZ = oversteekplaatsen[2];
            fietsOW = oversteekplaatsen[3];
            zebraNZ = oversteekplaatsen[4];
            zebraOW = oversteekplaatsen[5];

            autoNZ.teken();
            autoOW.teken();

            fietsNZ.teken();
            fietsOW.teken();

            zebraNZ.teken();
            zebraOW.teken();
        }

        private void Kruispunt_Load(object sender, EventArgs e)
        {

        }
    }
}
0

精彩评论

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

关注公众号