13-05-14, 08:15 AM
الكود أدناه عبارة عن Progress Indicator بسيط جدا و إن شاء الله يفي بإحتياجاتك.
كيف تستخدم الكود من داخل مشروعك:
1- افتح مشروع جديد ثم أضف الكود التالي له
2- قم بعمل build ثم اضف الكونترول الي الفورم
3- اضف Timer الي الفورم ثم اكتب الكود بالشكل التالي
كيف تستخدم الكود من داخل مشروعك:
1- افتح مشروع جديد ثم أضف الكود التالي له
2- قم بعمل build ثم اضف الكونترول الي الفورم
كود :
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Namespace RiverNile
'****************************************************************************************'
' Module Name: RiverNile.Indicator
' Project: ProgressIndicatorControl
' Copyright (c) RiverNile.Net.
' All other rights reserved. silverlight1212@yahoo.com
' The sample demonstrates how to buidl a simple progress indicator using backbufferd image
'
'
' This source is subject to the Public License.
' Follow my blog for future enhancement
'
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'****************************************************************************************'
Public Class Indicator
Inherits Control
Private _value As Long
Private _maximum As Long = 100
Public Sub New()
Me.Size = New Size(100, 100)
End Sub
Public Property Value() As Long
Get
Return _value
End Get
Set(value As Long)
If value > _maximum Then value = _maximum
_value = value
Invalidate()
End Set
End Property
Public Property Maximum As Long
Get
Return _maximum
End Get
Set(value As Long)
If value < 1 Then value = 1
_maximum = value
Invalidate()
End Set
End Property
''' <summary>
'''Not Applicaple, as buffered image will be handled by the code.
''' </summary>
''' <param name="pevent"></param>
''' <remarks></remarks>
Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
'MyBase.OnPaintBackground(pevent)
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
BufferDrawing.DrawProgressIndicator(e.Graphics, Me.Width, Me.Height, ControlPaint.Dark(Me.BackColor), Me.BackColor, 2, Me._maximum, Me._value, Me.Font)
End Sub
End Class ' Indicator
Public NotInheritable Class BufferDrawing
Friend Shared Sub DrawProgressIndicator(gr As Graphics, imgWidth As Integer, _
imgHeight As Integer, indicatorColor As Color, _
indicatorBackcolor As Color, thick As Integer, _
maxValue As Long, indicatorValue As Long, textFont As Font)
Using bmp As New Bitmap(imgWidth, imgHeight)
Using g As Graphics = Graphics.FromImage(bmp)
g.SmoothingMode = SmoothingMode.AntiAlias
g.SmoothingMode = SmoothingMode.HighQuality
g.Clear(indicatorBackcolor)
Using sb As New SolidBrush(indicatorColor)
Using indicatorPen As New Pen(sb, thick)
indicatorPen.StartCap = LineCap.Round
indicatorPen.EndCap = LineCap.Round
g.DrawArc(indicatorPen, CInt(thick / 2), CInt(thick / 2), imgWidth - thick - 1, imgHeight - thick - 1, 180, CInt((360 / maxValue) * indicatorValue))
End Using
End Using
Dim indicatorString As SizeF = g.MeasureString(CStr(CInt((100 / maxValue) * indicatorValue)), textFont)
g.DrawString(CStr(CInt((100 / maxValue) * indicatorValue)), textFont, Brushes.Black, CInt(imgWidth / 2 - indicatorString.Width / 2), CInt(imgHeight / 2 - indicatorString.Height / 2))
gr.DrawImage(bmp, 0, 0)
End Using
End Using
End Sub
End Class ' BufferDrawing
End Namespace ' RiverNileكود :
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Indicator1.Value += 1
Indicator1.Invalidate()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Start()
End Sub
End Class
