Opacity CheckBox(VisualStudio)不起作用

时间:2014-12-28 18:31:05

标签: c# visual-studio checkbox

没有代码问题,调试没有任何问题但是当我测试时,当我选中复选框时,不透明度不会改变。什么都没发生。我使用的是VisualStudio 2013 Express。这是代码:

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;
            }


        }
    }
}

1 个答案:

答案 0 :(得分:1)

代码似乎没有做任何正确的事情。您正在Form方法中创建checkBox1_CheckedChanged的新实例(为什么要创建新表单?),在新表单上设置Opacity属性,但不以任何方式显示表单。您需要致电Show()上的ShowDialog() / Form1来展示它。

如果您希望更改当前表单的不透明度,可以这样做:

this.Opacity = 1;

没有this之类的通话也会起作用:

Opacity = 1;
相关问题