2014-12-28 25 views
-2

沒有代碼問題,調試沒有任何問題,但是當我測試時,當我選中複選框時,不透明度不會改變。什麼都沒發生。我正在使用VisualStudio 2013 Express。代碼如下:不透明CheckBox(VisualStudio)不工作

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace TP3 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void textBox1_TextChanged(object sender, EventArgs e) 
     { 

      int carac = textBox1.Text.Length; 
      label2.Text = carac.ToString(); 

     } 

     private void label2_Click(object sender, EventArgs e) 
     { 




     } 

     private void checkBox1_CheckedChanged(object sender, EventArgs e) 
     { 
      Form Form1; 
      Form1 = new Form1(); 
      if(checkBox1.Checked == true) 
      { 
      Form1.Opacity = 1; 
      } 


     } 
    } 
} 
+2

你不應該需要創建一個新的窗體實例。 –

回答

1

該代碼似乎沒有做任何事情。您正在checkBox1_CheckedChanged方法中創建Form的新實例(爲什麼要創建一個新表單?),您在新表單上設置了Opacity屬性,但不以任何方式顯示錶單。您需要撥打Form1上的Show()/ShowDialog()進行顯示。

如果你想改變當前形式的不透明度,你可以這樣來做:

this.Opacity = 1; 

和呼叫就像沒有this會工作,以及:

Opacity = 1;