Image of a loop button in C #

I have a form in C # that has a button that, when clicked, I want the background image to cycle through a set of images (which I have as resources for the project). The images are called "_1", "_2", etc., And every time I press a button, I want its background image to increase to the next and return to "_1" when it reaches the highest. Is there any way to do this?

I tried to get it button1.BackgroundImage.ToString(), but it gives System.Drawing.Bitmapinstead Resources._1what I thought it would be (in this case, I could just get the last character and turn it on to change the background to the corresponding new image).

Thank you for your help.

+3
source share
3

?

+3

Button BackgroundImage, , . onclick, , , .

0
class YourClass
{
    private IEnumerator<Image> enumerator;

    YourClass(IEnumerable<Image> images)
    {
        enumerator = (from i in Enumerable.Range(0, int.Max)
                      from image in images
                      select image).GetEnumerator();
        enumerator.MoveNext();
    }

    public Image CurrentImage { get { return enumerator.Current; } }

    public void OnButtonClick() { enumerator.MoveNext(); }
}

, .

, . , .

0

Source: https://habr.com/ru/post/1696438/


All Articles