امروز اومدم پیش اعضا انجمن با یک مطلب جذاب .دوس دارید باهم برنامه ای بنویسیم که برف بیاد ؟ پس بالافاصله بریم سراغ کد نویسی!

خوب ابتدا کد زیر را در بالای فرم قرار بدید:
Dim را که دیگه میدونید کجا قرار بدید


Dim num, x(), y(), v(), s() As Integer
Dim random As Random = New Random
Dim graphics As System.Drawing.Graphics
Dim rectangle As Rectangle


حالا میریم دو شی ایجاد کنیم به صورت Random برف بیاد !



Private Sub Insnow(ByVal i As Integer)
x(i) = random.Next(0, Me.Width - 1)
y(i) = random.Next(0, Me.Height * 5 / 7)
v(i) = random.Next(5, 20)
s(i) = (random.Next(1, 3) * 100 + random.Next(50, 200)) / 100
End Sub




Private Sub snow()
num = 2000
ReDim x(num - 1)
ReDim y(num - 1)
ReDim v(num - 1)
ReDim s(num - 1)
Dim i As Integer
For i = 0 To num - 1
Insnow(i)
Next
End Sub


خوب یک تایمر روی اضافه کنید و داخلش کد زیرو بنویسید !



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static i As Integer
For i = 0 To num - 1
y(i) = y(i) + v(i)
If y(i) >= Me.Height Then
Insnow(i)
End If
Next
Invalidate()
End Sub




Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
graphics = e.Graphics
Dim i As Integer
For i = 0 To num - 1
graphics.FillEllipse(Brushes.White, x(i), y(i), s(i), s(i))
Next
End Sub




rectangle = New Rectangle(0, 0, Me.Width, Me.Height)


کد زیر را در Form_Load اضافه کنید !



Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.UpdateStyles()
snow()
Timer1.Start()


یک کلاس اضافه کنید و کد زیر را بهش اضافه کنید.



Public Class Form1

Dim num, x(), y(), v(), s() As Integer
Dim random As Random = New Random
Dim graphics As System.Drawing.Graphics
Dim rectangle As Rectangle

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.UpdateStyles()
snow()
Timer1.Start()
End Sub
Private Sub snow()
num = 2000
ReDim x(num - 1)
ReDim y(num - 1)
ReDim v(num - 1)
ReDim s(num - 1)
Dim i As Integer
For i = 0 To num - 1
Insnow(i)
Next
End Sub
Private Sub Insnow(ByVal i As Integer)
x(i) = random.Next(0, Me.Width - 1)
y(i) = random.Next(0, Me.Height * 5 / 7)
v(i) = random.Next(5, 20)
s(i) = (random.Next(1, 3) * 100 + random.Next(50, 200)) / 100
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static i As Integer
For i = 0 To num - 1
y(i) = y(i) + v(i)
If y(i) >= Me.Height Then
Insnow(i)
End If
Next
Invalidate()
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
graphics = e.Graphics
Dim i As Integer
For i = 0 To num - 1
graphics.FillEllipse(Brushes.White, x(i), y(i), s(i), s(i))
Next
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
End Sub
End Class


موفق باشید !