문제

C#의 버튼에 애니메이션 GIF를 추가하는 방법을 알려주시겠습니까? 자원에 GIF를 추가하고 버튼 이미지가 잘 작동하지 않았기 때문에 (다음 프레임에 대한 다음 프레임). 문제는 C#이 투명성을 처리하는 방식에있는 것 같습니다. 그러나 나는 그것을 고치는 방법을 모르겠습니다.

미리 감사드립니다.

--- 편집하다 ---

GIF를 사용한 후 문제는 GIF의 투명성에 관한 것이 었습니다. 다음 프레임은 이전 프레임 위에 그려 졌으므로 애니메이션 중간에 투명 해지고 싶었습니다. 솔루션은 다음 프레임에 흰색 영역을 만들기 위해 흰색 영역을 만드는 것이 었습니다. 흰색은 투명한 색 이었으므로 그 후 모든 것이 잘 보였습니다. :)

누군가가 유용해지기를 바랍니다. 행복한 프로그래밍 :)

도움이 되었습니까?

해결책 3

나는 그것을 작동시켰다.

두 가지 중 하나는 저에게 효과가있었습니다.

  1. 나는 모든 프레임에 속성을 추가하여 gif를 재조정하여 자체적으로 마비시켰다.

  2. VS 버전을 변경했습니다 (무료 전문 학생 버전을 사용하고 있었는데 지금은 MSDN 구독에서 사용하고 있습니다)

입력 담당자에게 감사합니다. 그것은 내 프로그래밍 스타일이 아니라 자체에 문제가 될 수 있다는 결론을 내렸다 :)

다른 팁

이렇게하려면 다음을 수행해야합니다.

  1. BackgroundImagelayout 속성을 중앙으로 설정하십시오. 이 속성은 기본적으로 타일로 설정됩니다.

  2. 버튼의 이미지 속성을 애니메이션 GIF로 설정하십시오.

테스트를 거쳤으므로 효과가있을 것입니다.

편집 : 아래에 게시 된 디자이너 코드 :

 this.Button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
 this.Button4.Image = (System.Drawing.Image)resources.GetObject("Button4.Image");
 this.Button4.Location = new System.Drawing.Point(220, 329);
 this.Button4.Name = "Button4";
 this.Button4.Size = new System.Drawing.Size(81, 68);
 this.Button4.TabIndex = 4;
 this.Button4.Text = "Button4";
 this.Button4.UseVisualStyleBackColor = true;

모든 사람에게 메모. GIF 애니메이션은 .image 속성에서 사용되지만 .BackgroundImage One에서 사용하지 않으면 자동으로 재생됩니다. 누군가가 그렇게 시도하는 경우를 대비하여.

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;
using System.Media;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        SoundPlayer sp = new SoundPlayer(@"1.wav");
        SoundPlayer s = new SoundPlayer(@"2.wav");

        private System.Windows.Forms.Label[] arLabel;
        int temp = 10;
        int help = 0;
        int r = 0, b = 0, a, tem = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            f1();
        }

          private void arLabel_Click(object sender, System.EventArgs e)
        {
            Label myButton = (Label)sender;


            if (myButton.Text == "")
            {

                myButton.ForeColor = System.Drawing.Color.Red;



                sp.Play();
                temp = 1;

                myButton.Text = "x".ToString();
                help = 0;
                f3();
            }
            for (int i = 0; i < arLabel.Length; i++)
            {
                if (arLabel[i].Text != "x")
                    this.arLabel[i].ForeColor = System.Drawing.Color.Green;
            }

            s.Play();
//------------------------------------------------------------------------------------------------------------------------------------

            if (temp == 1)
            {
                if (arLabel[6].Text == "" && arLabel[0].Text == "x" || arLabel[8].Text=="x"&&arLabel[6].Text=="")
                    arLabel[6].Text = "o".ToString();
                else if (arLabel[4].Text == "")
                    arLabel[4].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------

                else if (arLabel[0].Text == arLabel[1].Text && arLabel[2].Text == "")//
                    arLabel[2].Text = "o".ToString();
                else if (arLabel[0].Text == arLabel[2].Text && arLabel[1].Text == "")//
                    arLabel[1].Text = "o".ToString();
                else if (arLabel[1].Text == arLabel[2].Text && arLabel[0].Text == "")//
                    arLabel[0].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[6].Text == arLabel[7].Text && arLabel[8].Text == "")
                    arLabel[8].Text = "o".ToString();
                else if (arLabel[6].Text == arLabel[8].Text && arLabel[7].Text == "")
                    arLabel[7].Text = "o".ToString();
                else if (arLabel[8].Text == arLabel[7].Text && arLabel[6].Text == "")
                    arLabel[6].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[3].Text == arLabel[4].Text && arLabel[5].Text == "")
                    arLabel[5].Text = "o".ToString();
                else if (arLabel[3].Text == arLabel[5].Text && arLabel[4].Text == "")
                    arLabel[4].Text = "o".ToString();
                else if (arLabel[5].Text == arLabel[4].Text && arLabel[3].Text == "")
                    arLabel[3].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[0].Text == arLabel[3].Text && arLabel[6].Text == "")
                    arLabel[6].Text = "o".ToString();
                else if (arLabel[0].Text == arLabel[6].Text && arLabel[3].Text == "")
                    arLabel[3].Text = "o".ToString();
                else if (arLabel[6].Text == arLabel[3].Text && arLabel[0].Text == "")
                    arLabel[0].Text = "o".ToString();


//------------------------------------------------------------------------------------------------------------------------------------

                else if (arLabel[1].Text == arLabel[4].Text && arLabel[7].Text == "")
                    arLabel[7].Text = "o".ToString();
                else if (arLabel[1].Text == arLabel[7].Text && arLabel[4].Text == "")
                    arLabel[4].Text = "o".ToString();
                else if (arLabel[7].Text == arLabel[4].Text && arLabel[1].Text == "")
                    arLabel[1].Text = "o".ToString();
//------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[2].Text == arLabel[5].Text && arLabel[8].Text == "")
                    arLabel[8].Text = "o".ToString();
                else if (arLabel[8].Text == arLabel[5].Text && arLabel[2].Text == "")
                    arLabel[2].Text = "o".ToString();
                else if (arLabel[2].Text == arLabel[8].Text && arLabel[5].Text == "")
                    arLabel[5].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[0].Text == arLabel[4].Text && arLabel[8].Text == "")
                    arLabel[8].Text = "o".ToString();
                else if (arLabel[0].Text == arLabel[8].Text && arLabel[4].Text == "")
                    arLabel[4].Text = "o".ToString();
                else if (arLabel[8].Text == arLabel[4].Text && arLabel[0].Text == "")
                    arLabel[0].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else if (arLabel[2].Text == arLabel[4].Text && arLabel[6].Text == "")
                    arLabel[6].Text = "o".ToString();
                else if (arLabel[2].Text == arLabel[6].Text && arLabel[4].Text == "")
                    arLabel[4].Text = "o".ToString();
                else if (arLabel[4].Text == arLabel[6].Text && arLabel[2].Text == "")
                    arLabel[2].Text = "o".ToString();
                //------------------------------------------------------------------------------------------------------------------------------------
                else 
                    for (int i = 0; i < 9; i++)
                    {
                        if (arLabel[8].Text == "")
                        {
                            arLabel[8].Text = "o".ToString();
                            break;
                        }
                        else if (arLabel[7].Text == "")
                        {
                            arLabel[7].Text = "o".ToString();
                            break;
                        }
                        else if (arLabel[6].Text == "")
                        {
                            arLabel[6].Text = "o".ToString();
                            break;
                        }

 //------------------------------------------------------------------------------------------------------------------------------------
                        else if (arLabel[i].Text == "")
                        {
                            this.arLabel[i].ForeColor = System.Drawing.Color.Red;
                            arLabel[i].Text = "o";
                            break;
                        }

                    }

            }
            temp = 0;
            help = 1;
            f3();



        }










        private void f1()
        {
            this.arLabel = new Label[9];
            int b = 400;
            int c = 40;
            for (int i = 0; i < arLabel.Length; i++)
            {
                if (i == 3 || i == 6)
                {
                    c = c + 200;
                    b =400;
                }
                this.arLabel[i] = new Label();
                this.arLabel[i].Location = new System.Drawing.Point(b, c);
                this.arLabel[i].Size = new System.Drawing.Size(200, 200);
                this.arLabel[i].TabIndex = i;
                this.arLabel[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                this.arLabel[i].Text = "".ToString();
               arLabel[i].Click += new System.EventHandler(this.arLabel_Click);
                this.Controls.Add(arLabel[i]);
                this.arLabel[i].Font = new System.Drawing.Font("Modern No. 20", 120.74999F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.arLabel[i].ForeColor = System.Drawing.Color.Green;
                arLabel[i].Visible = true;
                this.arLabel[i].BackColor = System.Drawing.Color.Khaki;
                this.arLabel[i].BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                b = b + 200;
            }
        }
        private void f3()
        {
            if (arLabel[0].Text == arLabel[1].Text && arLabel[2].Text == arLabel[1].Text && arLabel[1].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            if (arLabel[3].Text == arLabel[4].Text && arLabel[3].Text == arLabel[5].Text && arLabel[3].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            if (arLabel[6].Text == arLabel[7].Text && arLabel[8].Text == arLabel[6].Text && arLabel[6].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            // if (arLabel[0].Text == arLabel[3].Text && arLabel[0].Text == arLabel[6].Text && arLabel[6].Text != "".ToString())
            // f2();
            if (arLabel[0].Text == arLabel[3].Text && arLabel[0].Text == arLabel[6].Text && arLabel[6].Text != "".ToString())
            {
                f2();
                temp = 0;
            }
            if (arLabel[1].Text == arLabel[4].Text && arLabel[4].Text == arLabel[7].Text && arLabel[7].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            if (arLabel[2].Text == arLabel[5].Text && arLabel[8].Text == arLabel[2].Text && arLabel[2].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            if (arLabel[0].Text == arLabel[4].Text && arLabel[4].Text == arLabel[8].Text && arLabel[8].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
            if (arLabel[2].Text == arLabel[4].Text && arLabel[6].Text == arLabel[4].Text && arLabel[4].Text != "".ToString())
            {
                temp = 0;
                f2();
            }
        }
        private void f2()
        {
            if (help == 1)
            {

                r++;
               // label4.Text = r.ToString();
                MessageBox.Show("THE is o");
                f6();
            }
            else
            {

                b++;

              //  label5.Text = b.ToString();
                MessageBox.Show("THE is x");
            }


            for (int i = 0; i < arLabel.Length; i++)

                arLabel[i].Text = "".ToString();
            f6();
        }
        private void f6()
        {
            Random number = new Random();
            a = number.Next(0, 8);
            this.arLabel[a].ForeColor = System.Drawing.Color.Green;
            arLabel[a].Text = "o".ToString();

            s.PlaySync();

        }
    }


}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top