السلام عليكم جميعا
اريد كود يعمل علي اغلاق الفورم vbبالتلاشي الشفافية
اشتغل معي الكود عند فتح الفورم لكن لم اعرف كيف اشغله عند الاغلاق
كود عند التشغيل :
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Me.Opacity = 0
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Opacity = Me.Opacity + 0.03
If Me.Opacity > 97 Then
Timer1.Enabled = False
End If
End Sub
End Class
--------------------------------------------------------------------------------------
بارك الله فيكم وجزالكم الله الف خير
نفس الكود بس بطريقة عكسية
في الاول الفورم يكون شفافيته 0 والتايمر يزيدها
في الاغلاق بتكون الشفافية 100 والتايمر ينقصها تدريجيا
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
'الغيها لان الفورم صارت شفافيته 97 او خليها تساوي 100
'Me.Opacity = 0
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Opacity = Me.Opacity - 0.03
If Me.Opacity < 3 Then
Timer1.Enabled = False
'هنا حط كود اغلاق البرنامج
End If
End Sub
End Class
ربي بحفظك اخي محمد كريم
الكود جربته لم بشتغل معي اريد عند اغلاق الفورم تتلاشي الشفافية ومن تم يتم الخروج من الفورم
هده الكودات الي درتها اني
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
If e.Cancel = True Then
Timer2.Enabled = True
End If
وفي التايمر
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Me.Opacity = Me.Opacity - 0.03
If Me.Opacity < 0.03 Then
Me.Close()
Timer2.Enabled = False
End If
End Sub
النتيجة يتلاشي الفورم لكن لا يتم غلقة
اضفت متغير بولياني في الفورم
Dim finish_closing As Boolean
حتى نخزن فيه الحالة لتجنب تنفيذ e.cancel لانها تمنع اغلاق الفورم
واستخدمت Application.Exit() بدلا من Me.Close()
هذا كود الفورم بالكامل
كود :
Public Class Form1
Dim finish_closing As Boolean
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If (finish_closing) Then
Application.Exit()
Else
e.Cancel = True
Timer2.Enabled = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Opacity = 0
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Opacity = Me.Opacity + 0.03
If Me.Opacity > 97 Then
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Me.Opacity -= 0.1
If Me.Opacity < 0.03 Then
finish_closing = True
Me.Close()
End If
End Sub
End Class
تعديل / هذا في حالة كان اغلاق هذا الفورم مراد به انهاء عمل البرنامج بالكامل
ويبدو ان استخدام Application.Exit() لا داعي له هنا
استبدله بـ
e.Cancel = False
PHP كود :
Public Class Form1
Private speed As Single = 2
Public Sub FadeFormOut()
For i = 100 To 0 Step -speed
Me.Opacity = i / 100
Me.Refresh()
Threading.Thread.Sleep(50)
Next
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
FadeFormOut()
End Sub
End Class
بارك الله فيك اخي محمد كريّم وجزالك الله الف خير
الحمد لله الكود 100% شغال
--------------------------------------------------
وشكر ليك silverlight وربي يوفقك ان شاء الله