تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تلاشي الصور في اداة picbox
#7
أضف الكلاس التالي لمشروعك و هو عبارة عن كونترول
PHP كود :
Imports System.ComponentModel
Imports System
.Drawing.Drawing2D

<DefaultProperty("Image"), DefaultEvent("Enter")>
Public Class 
ImageSlider
    Inherits Control

    Private _timer 
As New System.Timers.Timer()
 
   Private _img As Bitmap
    Private _sliding 
As Boolean False
    Private _startTime 
As DateTime
    Private seconds 
As Integer 3
    Private _speed 
As TimeSpan
    Private _percent 
As Integer 0
    Private _direction 
As SlideDirection SlideDirection.Left

    Public Sub 
New()
 
       MyBase.SetStyle(ControlStyles.ContainerControl Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.OptimizedDoubleBufferTrue)
 
       _speed = New TimeSpan(000seconds0)
 
       AddHandler _timer.ElapsedAddressOf TimerTick
    End Sub

    
<DefaultValue(GetType(SlideDirection), "Left")>
 
   <Description("Gets or set slide direction.")>
 
   <Category("Appearance")>
 
   Public Property Direction As SlideDirection
        Get
            Return _direction
        End Get
        Set
(value As SlideDirection)
 
           _direction value
            Invalidate
()
 
       End Set
    End Property

    
<DefaultValue(GetType(Bitmap), "")>
 
   <Description("Gets or set iamge.")>
 
   <Category("Appearance")>
 
   Public Property Image() As Bitmap
        Get
            Return _img
        End Get
        Set
(value As Bitmap)
 
           _img value
            Me
.Invalidate()
 
       End Set
    End Property

    Protected Overloads Overrides ReadOnly Property DefaultSize
() As Size
        Get
            Return 
New Size(150150)
 
       End Get
    End Property

    Public Sub Slide
()
 
       Me.Slide(42)
 
   End Sub

    Private Sub Slide
(interval As Integer)
 
       If interval 100 Then
            interval 
100
        End 
If
 
       _timer.Interval interval
        _timer
.Enabled True
        _percent 
0
        _startTime 
DateTime.Now
        _sliding 
True
        Invalidate
()
 
   End Sub

    Private Sub StopSliding
()
 
       _sliding False
        _timer
.Enabled False
    End Sub

    Protected 
Function DrawImage(As Graphicsrect As Rectangledirction As SlideDirection)
 
       If _img IsNot Nothing Then
            Dim mx 
As Matrix CType(NothingMatrix)
 
           If _sliding Then
                Select 
Case Direction
                    Case SlideDirection
.Down
                        mx 
= New Drawing2D.Matrix(10010, (rect.Height _percent 100) - rect.Height)
 
                       Exit Select

                    Case SlideDirection
.Left
                        mx 
= New Drawing2D.Matrix(1001, -(rect.Width _percent 100) + rect.Width0)
 
                       Exit Select

                    Case SlideDirection
.Right
                        mx 
= New Drawing2D.Matrix(1001, (rect.Width _percent 100) - rect.Width0)
 
                       Exit Select

                    Case SlideDirection
.Top
                        mx 
= New Drawing2D.Matrix(10010, -(rect.Height _percent 100) + rect.Height)
 
                       Exit Select
                End Select
                g
.Transform mx
                g
.DrawImage(_imgrect00_img.Width_img.HeightGraphicsUnit.Pixel)
 
               If mx IsNot Nothing Then
                    mx
.Dispose()
 
               End If
 
           Else
                g
.DrawImage(_imgrect00_img.Width_img.HeightGraphicsUnit.Pixel)
 
           End If

 
       End If
 
   End Function

 
   Private Sub TimerTick(source As ObjectAs System.Timers.ElapsedEventArgs)
 
       Dim span As TimeSpan DateTime.Now _startTime
        _percent 
CSng((100.0F _speed.TotalSeconds span.TotalSeconds))
 
       If _percent 100 Then
            _percent 
100
        End 
If
 
       Invalidate()
 
   End Sub

    Protected Overrides Sub OnPaint
(As PaintEventArgs)
 
       MyBase.OnPaint(e)
 
       Dim rect As Rectangle ClientRectangle
        Using borderPen 
As Pen = New Pen(If(Me.BackColor.GetBrightness 0SystemColors.ControlLightSystemColors.ControlDark))
 
           e.Graphics.DrawRectangle(borderPenrect.Xrect.Yrect.Width 1rect.Height 1)
 
       End Using

        rect
.+= 2
        rect
.+= 2
        rect
.Width -= 4
        rect
.Height -= 4
        Me
.DrawImage(e.Graphicsrect_direction)

 
   End Sub

    Protected Overrides Sub Dispose
(disposing As Boolean)
 
       MyBase.Dispose(disposing)
 
       RemoveHandler _timer.ElapsedAddressOf TimerTick
        If _timer IsNot Nothing Then
            _timer
.Dispose()
 
           _timer Nothing
        End 
If
 
   End Sub

    Public Enum SlideDirection
        Left
        Right
        Top
        Down
    End Enum

End 
Class 

اغمل Build للكلاس بعدها ستجده في ToolBox الخاصة ب الفيجوال استوديو
اسحب الكونترول الي الفورم
أضف صورة للكونترول من خلال Property إسمها Image
حدد إتجاه حركة الصور من Property إسمها Direction

في الحدث Enter الخاص بالكونترول

اكتب الكود بالشكل التالي


PHP كود :
   Private Sub ImageSlider1_Enter(sender As ObjectAs EventArgsHandles ImageSlider1.Enter
        Dim slider 
As ImageSlider CType(senderImageSlider)
 
       slider.Direction ImageSlider.SlideDirection.Top
        slider
.Slide()
 
   End Sub 
في الكود هنا انا غيرت الاتجاه لأوضح لك كيفية تغيير اتجاه الحركة برمجيا
Retired
الرد }}}


الردود في هذا الموضوع
RE: تلاشي الصور في اداة picbox - بواسطة silverlight - 27-12-17, 02:45 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم