2009-05-05 6 views
2

C#의 단추에 애니메이션 gif를 추가하는 방법을 알려주시겠습니까? 리소스에 gif를 추가하고 단추 이미지가 제대로 작동하지 않아서 설정이 변경되었습니다 (이전 프레임보다 다음 프레임이 우선 됨). 문제는 C#이 투명성을 다루는 방식 인 것처럼 보이지만 문제를 해결하는 방법을 모르겠습니다.애니메이션 GIF를 버튼에 추가하는 방법은 무엇입니까?

미리 감사드립니다.

--- 편집 ---

있는 GIF와 함께 연주 후 문제는 GIF의 투명성과 함께했다. 다음 프레임은 이전 프레임 위에 그려져있어서 애니메이션 중간에 투명하게 되길 원했던 요소가 제대로 작동하지 않았습니다 (여전히 이전 프레임의 색상을 가짐). 해결책은 이전 프레임을 덮기 위해 다음 프레임에 흰색 영역을 생성하는 것이 었습니다. 흰색은 내 투명 색상 이었으므로 모든 것이 잘 보였습니다. :)

누군가가 유용하다고 생각하길 바랍니다. 해피 프로그래밍 :

+1

왜이 작업을 수행하고 있습니까? –

+0

버튼은 취소 버튼입니다. 애니메이션은 진행 상황을 나타내야합니다 (사용자가 프로그램이 추락하지 않을 정도로 움직여야합니다). 백그라운드 작업자가 작업 할 때 버튼이 표시되고 cancelasync 메소드가 트리거됩니다. – kyrisu

+0

마키 모드에서 진행률 막대를 표시하지 않으시겠습니까? 회전하는 애니메이션 GIF (또는 무엇이든)를 사용하는 앱을 보았고 아마 항상 최신 OS 테마에 맞게 조정되지 않은 아마추어 B/C를 거의 항상 보입니다. 진행률 표시 줄이 나타납니다. –

답변

1

나는 그것을 작동시켜야합니다. 2 가지의

1은 나를 위해 일한 : 나는 자신을 열어 젖히다하는 모든 프레임에 속성을 추가 GIF를 재 편집 한

  1. .

  2. 나는 VS 버전 (내가 지금은 MSDN 구독에서 하나를 사용하고 있습니다 , 무료 전문 학생 버전을 사용했다) 입력들에 대한

감사를 변경했습니다. 그것은 내 프로그래밍 스타일이 아닌 VS 자체에 문제가 있다는 결론을 내 렸습니다.

2

이를 위해, 당신은 다음을 수행해야합니다

  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; 
+0

불행히도 그것은 나를 위해 작동하지 않았습니다. 아마도 그것은 gif 형식의 원인입니다 (애니메이션을 미리보기에 추가 할 때 애니메이션이 반드시 있어야하는 것은 아니지만 브라우저에서는 정상적으로 작동합니다) – kyrisu

+0

이상하게도 작동하지 않습니다. GIF를 어딘가에 온라인으로 게시하고 싶다면, 볼 수 있습니다. – jgallant

+0

Heres the link : http://wyslijto.pl/plik/b0p7cub92x 고마워요 :) – kyrisu

2

그냥 메모를 모두에게. .Image 속성에는 사용되지만 .BackGroundImage 속성에는 사용되지 않으면 GIF 애니메이션이 자동으로 재생됩니다. 누군가가 그런 식으로 노력하고있는 경우에 대비해.

+0

Jon 코드 : this.Button4.BackgroundImageLayout은 .Image의 레이아웃에 영향을 미치지 않습니다. –

1
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(); 

     } 
    } 


} 
관련 문제