Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows窗体淡入效果问题VB.Net_Vb.net_Project_Fadein - Fatal编程技术网

Windows窗体淡入效果问题VB.Net

Windows窗体淡入效果问题VB.Net,vb.net,project,fadein,Vb.net,Project,Fadein,我对Windows窗体的淡入淡出效果有问题。 此表单应读取文件的值并将其存储在变量中,然后启动计时器,将表单的不透明度增加到读取的值,但不会发生这种情况 我尝试了两种方法将值存储在变量中,第一种: If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Users\" & My.Settings.username & "\opacity.goodsetting") Then Try

我对Windows窗体的淡入淡出效果有问题。 此表单应读取文件的值并将其存储在变量中,然后启动计时器,将表单的不透明度增加到读取的值,但不会发生这种情况

我尝试了两种方法将值存储在变量中,第一种:

If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Users\" & My.Settings.username & "\opacity.goodsetting") Then
        Try
            Using read As New StreamReader(Application.StartupPath & "\Users\" & My.Settings.username& "\opacity.goodsetting")
                If read.ReadLine = "50" Then
                    varOpacity = 0.5
                ElseIf read.ReadLine = "60" Then
                        varOpacity = 0.6
                ElseIf read.ReadLine = "70" Then
                        varOpacity = 0.7
                ElseIf read.ReadLine = "80" Then
                        varOpacity = 0.8
                ElseIf read.ReadLine = "90" Then
                        varOpacity = 0.9
                ElseIf read.ReadLine = "100" Then
                        varOpacity = 1
                End If
                read.Close()
                End Using
        Catch ex As Exception
            varOpacity = 1
            Me.Opacity = 1
        End Try
End If
Timer2.Start()
第二点:

Try
    varOpacity = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Users\" & My.Settings.username & "\opacity.goodsetting")
    Me.Opacity = varOpacity / 100
Catch ex As Exception
    varOpacity = 1
    Me.Opacity = 1
End Try
但这两种方法都不起作用

我还留下了效果代码:

Me.Opacity = Me.Opacity + 0.1
If Me.Opacity = varOpacity Then
    Timer2.Stop()
End If

谢谢大家。

这是一个我认为你想要的例子。。。 我试着让它尽可能接近你最初的例子。 出于测试目的,我将代码放在了加载的形式,并添加了一个计时器。 希望你能根据自己的需要进行测试和改变

表单需要在设计器中将其
不透明度设置为0。
代码将从0淡入到存储在文件中的值,否则默认为1

代码已导入System.IO

Private varOpacity As Double

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    'Set the path just once.
    Dim pathOpacityLimit As String = Path.Combine(Application.StartupPath & "\Users\" & My.Settings.username, "opacity.goodsetting")
    If File.Exists(pathOpacityLimit) Then
        Try
            Using read As New StreamReader(pathOpacityLimit)
                If Double.TryParse(read.ReadLine, varOpacity) Then
                    'Value parsed - changed to 0.0 > 1.0 so inline with Me.Opacity. Start timer.
                    varOpacity /= 100
                    Timer2.Start()
                Else
                    'Incorrect (not parsed) value in file - set default
                    Me.Opacity = 1
                End If
                read.Close()
            End Using
        Catch ex As Exception
            'Exception - set default
            Me.Opacity = 1
        End Try
    Else
        'File doesn't exist - set default
        Me.Opacity = 1
    End If
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    Me.Opacity += 0.1
    If Me.Opacity < varOpacity Then Exit Sub
    Me.Opacity = varOpacity
    Timer2.Stop()
End Sub
Private varOpacity为双精度
私有子表单1_Load(发送方作为对象,e作为事件参数)处理Me.Load
'只设置一次路径。
Dim PathCapacityLimit为String=Path.Combine(Application.StartupPath&“\Users\”和My.Settings.username,“opacity.goodsetting”)
如果File.Exists(pathOpacityLimit)存在,则
尝试
使用read作为新的StreamReader(PathCapacityLimit)
如果是Double.TryParse(read.ReadLine,varOpacity),那么
'值已解析-更改为0.0>1.0,因此与Me.Opacity内联。启动计时器。
不透明度/=100
Timer2.Start()
其他的
'文件中的值不正确(未解析)-设置为默认值
Me.Opacity=1
如果结束
read.Close()
终端使用
特例
'异常-设置默认值
Me.Opacity=1
结束尝试
其他的
'文件不存在-设置默认值
Me.Opacity=1
如果结束
端接头
私有子Timer2_Tick(发送方作为对象,e作为事件参数)处理Timer2。Tick
Me.Opacity+=0.1
如果Me.Opacity

我希望这足以让你开始。您还可以检查存储的值,看看它是否在所需的0到100范围内。

什么类型的计时器是
timer2
?你应该展示一下定时器是如何工作的。将
选项设置为Strict On
,更正所有扭曲的内容,然后重试。(使用显式实例化的
System.Windows.Form.Timer
)。而且,它也不起作用,这并不是一个很好的描述。还要使此描述更加明确。重复调用ReadLine()是一个错误。只调用一次,将其返回值存储在变量中。然后检查变量值。在
Application.StartupPath&“\Users\”&My.Settings.username&“\opacity.goodsetting”
上执行
Debug.Print
MessageBox.Show
,然后检查该位置是否确实有文件。