简体   繁体   English

打开表单时更改窗口不透明度

[英]Change window opacity when opening a form

I'm trying to change a Form's opacity automatically before loading. 我正在尝试在加载之前自动更改Form的不透明度。 I am using built in Settings function to save the value what opacity the window should have. 我使用内置的设置功能来保存窗口应具有的不透明度的值。 The problem is, when I'm debugging my application, it all works well, when I compile it and try to open the executable, the window just dissapears... I don't get any errors. 问题是,当我调试我的应用程序时,一切正常,当我编译它并尝试打开可执行文件时,窗口就消失了......我没有得到任何错误。

This is how I'm trying to do it: 这就是我试图这样做的方式:

First there is a value in settings called opacity (int) from 0-100 首先,在0-100的设置中有一个名为opacity (int)的值

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Opacity = WindowsFormsApplication1.Properties.Settings.Default.opacity * 0.01;
    }

When you debug, the settings that you save will be kept from run to run. 调试时,保存的设置将保持运行状态。 When you deploy, it will copy the default settings file. 部署时,它将复制默认设置文件。

Do a check to see if the settings file opacity is actually being loaded correctly when you run the release exe. 运行release exe时,请检查设置文件的不透明度是否实际正确加载。 I have a feeling that either the default is 0, or it's not being loaded. 我觉得默认值为0,或者没有加载。

Your problem is that the Opacity value has 1.0 as fully visible, and 0.0 as fully invisible. 您的问题是不透明度值为1.0完全可见,0.0为完全不可见。 Anything above 1.0 counts as fully visible, too. 任何高于1.0的东西都算完全可见。


EDIT 编辑

ok, so after re-reading your question... maybe instead of using the default, use a constant like 0.5 to test it. 好的,所以在重新阅读你的问题之后...也许不使用默认值,使用0.5之类的常量来测试它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM