Home > DeveloperSection > Forums > Can I create this type of event in C#?
C G E Mannerheim
C G E Mannerheim

Total Post:29

Points:203
Posted on    August-10-2013 5:15 AM

 C# C# 
Ratings:


 1 Reply(s)
 1055  View(s)
Rate this:

I have a List in my custom user control. I'd like the control to redraw the each Image in the List whenever the contents of that list is changed. Either a movement, addition or removal of an items should fire an event.

 using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WebServiceScanner

{

    public partial class imageList : UserControl

    {

        public imageList()

        {

            InitializeComponent();

        }

 

        public List<Image> Images { get; set; }

 

        public void AddImage(Image image)

        {

            Images.Add(image);

        }

 

        public void RemoveImage(Image image)

        {

            Images.Remove(image);

        }

 

        public void MoveImageLeft(int index)

        {

            Image tmpImage = Images[index];

            Images[index] = Images[index - 1];

            Images[index - 1] = tmpImage;

        }

 

        public void MoveImageLeft(int index)

        {

            Image tmpImage = Images[index];

            Images[index] = Images[index + 1];

            Images[index + 1] = tmpImage;

        }

    }

}

 

Can this be done?

 

Thanks for your guidance! Eager to learn!



Pravesh Singh

Total Post:411

Points:2881
Posted on    August-10-2013 5:28 AM

public partial class imageList : UserControl

    {

 

        public event OnChange;

 

        public imageList()

        {

            InitializeComponent();

        }

 

        public List<Image> Images { get; set; }

 

        public void AddImage(Image image)

        {

            Images.Add(image);

            this.OnChange();

        }

 

        public void RemoveImage(Image image)

        {

            Images.Remove(image);

            this.OnChange();

        }

 

        public void MoveImageLeft(int index)

        {

            Image tmpImage = Images[index];

            Images[index] = Images[index - 1];

            Images[index - 1] = tmpImage;

            this.OnChange();

        }

 

        public void MoveImageLeft(int index)

        {

            Image tmpImage = Images[index];

            Images[index] = Images[index + 1];

            Images[index + 1] = tmpImage;

            this.OnChange();

        }

    }


Don't want to miss updates? Please click the below button!

Follow MindStick