PDA

View Full Version : Opacity برای کنترل های فرم



asilverisis
سه شنبه 02 تیر 1388, 11:21 صبح
سلام
آیا میشه برای کنترل های فرم مثل Panel یا GridView به هر نحوی Opacity رو تغییر داد.

طوری که اگر Opacity رو برای Panel تغغیر دادم تمام کنترل های روی اون هم شفاف تر بشن.
در واقع من می خوام با استفاده از یک Timer کنترل های روی فرم به صورت Fade نمایش بدم، نه خود فرم رو.

shahrdar
سه شنبه 02 تیر 1388, 15:06 عصر
دوست عزيز من خيلی دنبالش گشتم. کد هايی هم پيدا کردم ولی هيچ کدوم درست کار نميکردن.به اين نتيجه رسيدم که از wpf استفاده کنم

sari-1369
سه شنبه 02 تیر 1388, 17:08 عصر
سلام

این ضمیمه که واست گزاشتم ، توش یه کلاسه که میتونه کنترل هارو fade کنه . ( کار یکی از دوستان توی p30world )

sari-1369
سه شنبه 02 تیر 1388, 17:08 عصر
اینم کد کامل این کلاس .



Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms

Public Class Fading
Dim PicBox As New PictureBox
Private m_Alpha As Single = 1
Public Speed As Single = 8

Public Sub Fade(ByVal Control As Control)
If TypeOf Control Is Form Then Exit Sub
If Speed < 1 Then Speed = 1
If Speed > 100 Then Speed = 100
Speed = Speed / 1000

If Control.Visible Then
Fade_Out(Control)
Else
Fade_In(Control)
End If
End Sub
Private Sub Fade_Out(ByVal Control As Control)
PicBox.Parent = Control.Parent
PicBox.Size = Control.Size
PicBox.BorderStyle = BorderStyle.None
PicBox.Location = Control.Location
PicBox.Visible = True
Control.Visible = False

Dim bm1 As New Bitmap(PicBox.Width, PicBox.Height)
Control.DrawToBitmap(bm1, New Rectangle _
(0, 0, Control.Width, Control.Height))

Dim image_attr As New ImageAttributes
Dim cm As ColorMatrix
Dim rect As Rectangle = Rectangle.Round _
(bm1.GetBounds(GraphicsUnit.Pixel))

Dim bm As New Bitmap(bm1.Width, bm1.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
m_Alpha = 1
While m_Alpha > 0

m_Alpha -= Speed
cm = New ColorMatrix(New Single()() { _
New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, m_Alpha, 1.0}})
image_attr.SetColorMatrix(cm)
gr.DrawImage(bm1, rect, 0, 0, bm1.Width, bm1.Height _
, GraphicsUnit.Pixel, image_attr)
PicBox.Image = bm
Application.DoEvents()
cm = Nothing
gr.Clear(Color.Transparent)
End While

PicBox.Visible = False
PicBox.Image = Nothing
'--------------------------------------------------------------------
End Sub
Private Sub Fade_In(ByVal Control As Control)
PicBox.Parent = Control.Parent
PicBox.Size = Control.Size
PicBox.BorderStyle = BorderStyle.None
PicBox.Location = Control.Location
PicBox.Visible = True


Dim bm1 As New Bitmap(PicBox.Width, PicBox.Height)
Control.DrawToBitmap(bm1, New Rectangle _
(0, 0, Control.Width, Control.Height))

Dim image_attr As New ImageAttributes
Dim cm As ColorMatrix
Dim rect As Rectangle = Rectangle.Round _
(bm1.GetBounds(GraphicsUnit.Pixel))

Dim bm As New Bitmap(bm1.Width, bm1.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
m_Alpha = 0
While m_Alpha < 1

m_Alpha += Speed
cm = New ColorMatrix(New Single()() { _
New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, m_Alpha, 1.0}})
image_attr.SetColorMatrix(cm)
gr.DrawImage(bm1, rect, 0, 0, bm1.Width, bm1.Height, _
GraphicsUnit.Pixel, image_attr)
PicBox.Image = bm

Application.DoEvents()
cm = Nothing
gr.Clear(Color.Transparent)
End While

PicBox.Visible = False
Control.Visible = True

End Sub

End Class