Opacity CheckBox(VisualStudio)不起作用
本文关键字:不起作用 VisualStudio CheckBox Opacity | 更新日期: 2023-09-27 18:35:39
没有
代码问题,调试没有任何问题,但是当我测试时,当我选中复选框时,不透明度不会改变。什么也没发生。我正在使用 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;
}
}
}
}
代码似乎没有做任何正确的事情。您正在 checkBox1_CheckedChanged
方法中创建Form
的新实例(为什么要创建新窗体?),在新窗体上设置 Opacity 属性,但不以任何方式显示该窗体。您需要在Form1
上拨打Show()
/ShowDialog()
才能显示它。
如果您希望更改当前表单的不透明度,可以通过以下方式进行:
this.Opacity = 1;
像没有this
这样的电话也可以工作:
Opacity = 1;