آناهیتا جون اینجا جای مطرح کردن سوالات متفرقه نیست. قرار شد در این تاپیک راجع به کامپوننتهایی که خودمون ساختیم صحبت کنیم. سوالت رو در جای مناسب مطرح کن تا به آن پاسخ داده شود.نقل قول:
ممنون.
Printable View
آناهیتا جون اینجا جای مطرح کردن سوالات متفرقه نیست. قرار شد در این تاپیک راجع به کامپوننتهایی که خودمون ساختیم صحبت کنیم. سوالت رو در جای مناسب مطرح کن تا به آن پاسخ داده شود.نقل قول:
ممنون.
سلام
خیلی تاپیک جالبی باز کردین اگه ممکن ادامه بدین
--------------------------------------------------------------------------
چند روز پیش یه پروژه رو داشتم مینوشتم که بعضی جاها نیاز داشت که
کد نویسی تکراری کنم به خاطر همین گفتم به خودم بهتره از کلاسس textbox
به ارث ببرم و یه کلاسس به نام mjttextbox بر حسب نیاز خودم بنویسم . ولی به اون شکل کامل نیست
خواصی که بهش اضافه کردم :
اگه خاصیت tarikh استفاده کنید تاریخ شمسی رو به همراه ماه و روز بر میگردونه
اگه از خاصیت mahdod استفاده کنید میتونید اعداد و حروف رو ف.ی.ل.ت.ر کنید بر اساس نیازخود
اگه از خاصیت zaban استفاده کنید میتونید زبان mjttextbox رو به فارسی تغییر دهید بر اساس نیاز خود
اگه از خاصیت argham استفاده کنید میتونید سه رقم سه رقم اعداد رو جدا کنید .
سعی میکنم کامل ترش کنم
دانلود سورس به همراه DLL با حجم 40 کیلوبایت
دانلود از rapidکد:http://chetmaghz.parsaspace.com/mjttextbox.rar
فعلا به خاطر تنگی وقت نمیتونم بند دوم رو اجرا کنم در اولین فرصت این کار رو میکنمکد:http://rapidshare.com/files/109970065/mjttextbox.rar.html
این هم از سورس کامل ری سایزر که قبلا در همین سایت معرفی شده بود. آموزش چندانی نمیخواد چون خیلی ساده هستش.
بزودی : سورس کامل کامپوننت تقویم شمسی و ساعت آنالوگ.کد:
'Writen By Shalineh
Public Class ReSizer
Inherits System.ComponentModel.Component
Dim IsMouseDown As Boolean = False
Const W As Byte = 4
Public Sub Add(ByVal Control As Control)
Try
AddHandler Control.MouseMove, AddressOf Control_MouseMove
AddHandler Control.MouseDown, AddressOf Control_MouseDown
AddHandler Control.MouseUp, AddressOf Control_MouseUp
AddHandler Control.Parent.MouseUp, AddressOf Control_MouseUp
AddHandler Control.TopLevelControl.MouseUp, AddressOf Control_MouseUp
Catch ex As Exception
End Try
End Sub
Public Sub Remove(ByVal Control As Control)
Try
RemoveHandler Control.MouseMove, AddressOf Control_MouseMove
RemoveHandler Control.MouseDown, AddressOf Control_MouseDown
RemoveHandler Control.MouseUp, AddressOf Control_MouseUp
Catch ex As Exception
End Try
End Sub
Private Sub Control_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)
Dim C As Control = sender
Set_Element(sender, e, True)
If Pos = Position.None Then Moving(e, sender)
If IsMouseDown = False Then Exit Sub
Select Case Pos
Case Position.Right
C.SetBounds(C.Left, C.Top, C.Width - _
(C.Width - e.X), C.Height)
Case Position.Left
C.SetBounds(C.Left + e.X, C.Top, _
C.Width - e.X, C.Height)
Case Position.Top
C.SetBounds(C.Left, C.Top + e.Y, _
C.Width, C.Height - e.Y)
Case Position.Buttom
C.SetBounds(C.Left, C.Top, C.Width, _
C.Height - (C.Height - e.Y))
Case Position.TopLeft
C.SetBounds(C.Left + e.X, C.Top + e.Y, _
C.Width - e.X, C.Height - e.Y)
Case Position.TopRight
C.SetBounds(C.Left, C.Top + e.Y, C.Width - _
(C.Width - e.X), C.Height - e.Y)
Case Position.ButtomLeft
C.SetBounds(C.Left + e.X, C.Top, C.Width - e.X, _
C.Height - (C.Height - e.Y))
Case Position.ButtomRight
C.SetBounds(C.Left, C.Top, C.Width - (C.Width - e.X), _
C.Height - (C.Height - e.Y))
End Select
End Sub
Enum Position
None = 0
Right = 1
Left = 2
Top = 3
Buttom = 4
TopRight = 5
TopLeft = 6
ButtomRight = 7
ButtomLeft = 8
End Enum
Dim Pos As Position = Position.None
Private Sub Control_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)
Pos = Position.None
IsMouseDown = False
End Sub
Private Sub Control_MouseDown(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Set_Element(sender, e, False)
IsMouseDown = True
End Sub
Private Sub Set_Element(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs, ByVal Element As Boolean)
Dim C As Control = sender
If Element = True Then GoTo SetCursur
If e.X >= C.Width - W And e.Y >= W And e.Y <= _
C.Height - W Then Pos = Position.Right : Exit Sub 'Right
If e.X <= W And e.Y >= W And e.Y <= C.Height - _
W Then Pos = Position.Left : Exit Sub 'Left
If e.Y <= W And e.X >= W And e.X <= C.Width - _
W Then Pos = Position.Top : Exit Sub 'Top
If e.Y >= C.Height - W And e.X >= W And e.X <= C.Width - _
W Then Pos = Position.Buttom : Exit Sub 'Button
If e.X > C.Width - W And e.Y < W Then Pos = _
Position.TopRight : Exit Sub 'TopRight
If e.X < W And e.Y < W Then Pos = Position.TopLeft : Exit Sub 'TopLeft
If e.Y > C.Height - W And e.X > C.Width - W Then Pos = _
Position.ButtomRight : Exit Sub 'ButtonRight
If e.Y > C.Height - W And e.X < W Then Pos = _
Position.ButtomLeft : Exit Sub 'ButtonLeft
Pos = Position.None
SetCursur:
If e.X >= C.Width - W And e.Y >= W And e.Y <= _
C.Height - W Then C.Cursor = Cursors.SizeWE : Exit Sub 'Right
If e.X <= W And e.Y >= W And e.Y <= _
C.Height - W Then C.Cursor = Cursors.SizeWE : Exit Sub 'Left
If e.Y <= W And e.X >= W And e.X <= _
C.Width - W Then C.Cursor = Cursors.SizeNS : Exit Sub 'Top
If e.Y >= C.Height - W And e.X >= W And e.X <= _
C.Width - W Then C.Cursor = Cursors.SizeNS : Exit Sub 'Button
If e.X > C.Width - W And e.Y < W Then C.Cursor = _
Cursors.SizeNESW : Exit Sub 'TopRight
If e.X < W And e.Y < W Then C.Cursor = _
Cursors.SizeNWSE : Exit Sub 'TopLeft
If e.Y > C.Height - W And e.X > C.Width - W Then C.Cursor = _
Cursors.SizeNWSE : Exit Sub 'ButtonRight
If e.Y > C.Height - W And e.X < W Then C.Cursor = _
Cursors.SizeNESW : Exit Sub 'ButtonLeft
C.Cursor = Cursors.Default
End Sub
Private Sub Moving(ByVal e As MouseEventArgs, ByVal Control As Control)
Static OldPosition As New Point(-1, -1)
If Not (e.Button = Nothing) Then
If e.Button = Windows.Forms.MouseButtons.Left Then
If (OldPosition.X = -1) And (OldPosition.Y = -1) Then OldPosition = _
New Point(e.X, e.Y)
If e.Y <> OldPosition.Y Then
Control.Top += e.Y - OldPosition.Y 'move Up/Down
End If
If e.X <> OldPosition.X Then
Control.Left += e.X - OldPosition.X 'move Left/Right
End If
End If
Else
OldPosition = New Point(-1, -1)
End If
End Sub
End Class
خواهش میکنم. امیدوارم با همراهی دوستان خوبی چون شما ادامه داشته باشه.نقل قول:
نوشته شده توسط fozool.mohammad javad [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
خیلی خیلی زیبا بود. حتما کاملش کن و همینجا معرفی کن و آموزش بده.نقل قول:
نوشته شده توسط fozool.mohammad javad [ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
ممنون.
بدلیل طولانی بودن این سورس در چندین بخش ارائه میشود و نیز به خاطر پیچیده بودن سورس کد، از توضیحات صرف نظر میکنم. ولی با کمال میل به سوالات دوستان در جاهای مبهم پاسخ خواهم داد. :20:
بر روی یوزر کنترل یک لیبل به نام lab1 با پراپرتیهای AutoSize=True و Visible=False قرار دهید و نام کلاس رو در پنجره Solution Explorer به Analog.Vb تغییر دهید. نام کنترل رو هم در پنجره properties به Analog تغییر دهید.
علاوه بر لیبل یاد شده یک تایمر به نام Timer1 به کنترل اضافه کنید و در پنجره properties خاصیت های زیر مربوط به این تایمر رو بصورت زیر ست کنید:
Enabled=True و Interval=1000 .
به بخش کد ادیتور بروید و هر کدی که میبینید را پاک کنید. حتی بخش معرفی کلاس رو و این کدهایی رو که در چندین بخش ارائه خواهد شد رو به ترتیب بخش آنجا کپی کنید.
ادامه دارد ...کد:
Imports system.ComponentModel
<System.ComponentModel.DefaultEvent("MinuteChanged")> _
Public Class Analog
#Region "Var"
Dim MatrixSec As New System.Drawing.Drawing2D.Matrix
Dim MatrixMin As New System.Drawing.Drawing2D.Matrix
Dim MatrixHour As New System.Drawing.Drawing2D.Matrix
Dim Second_Color As Color = Color.Red
Dim Minute_Color As Color = Color.Black
Dim Hour_Color As Color = Color.Black
Dim PenSec As New Pen(Second_Color, Me.Width / 133)
Dim PenMin As New Pen(Minute_Color, Me.Width / 70)
Dim PenHour As New Pen(Hour_Color, Me.Width / 50)
Dim Rect As New Rectangle
Dim Path As New System.Drawing.Drawing2D.GraphicsPath
Dim MyRegion As Region
Dim sec As Byte = Now.Second
Dim Min As Byte = Now.Minute
Dim Hour As Byte = Now.Hour
Dim EventMin As Byte = Now.Minute
Dim EventHour As Byte = Now.Hour
Dim FrameWidth As Single = (Me.Width) * (Frame_Thickness / 100)
Dim MyFormat As New StringFormat
Dim MonthName As String() = {"Jan", "Feb", "Mar", _
"Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
#End Region
Public Event MinuteChanged()
Public Event HourChanged()
Public Event SecondChanged()
#Region "Properties"
Dim Frame_Thickness As Single = 8.5
<Category("Clock"), DefaultValue(8.5)> _
Public Property FrameThickness() As Single
Get
Return Frame_Thickness
End Get
Set(ByVal value As Single)
If value > 30 Then value = 30
If value <= 0 Then value = 0
Frame_Thickness = value
FrameWidth = (Me.Width) * (Frame_Thickness / 100)
Me.Invalidate()
End Set
End Property
Dim HatchStyle As Drawing2D.HatchStyle = Drawing2D.HatchStyle.LightHorizontal
<Category("Clock"), DefaultValue(Drawing2D.HatchStyle.LightHorizontal)> _
Public Property FrameStyle() As Drawing2D.HatchStyle
Get
Return HatchStyle
End Get
Set(ByVal value As Drawing2D.HatchStyle)
HatchStyle = value
Me.Invalidate()
End Set
End Property
Enum F_Mode
Circular = 1
QuadrAngular = 2
End Enum
Dim Frame_Mode As F_Mode = F_Mode.QuadrAngular
<Category("Clock"), DefaultValue(F_Mode.QuadrAngular)> _
Public Property FrameMode() As F_Mode
Get
Return Frame_Mode
End Get
Set(ByVal value As F_Mode)
Frame_Mode = value
SetRegion()
Me.Invalidate()
End Set
End Property
Dim Frame_BackColor As Color = Color.Gray
<Category("Clock"), DefaultValue("Black")> _
Public Property FrameBackColor() As Color
Get
Return Frame_BackColor
End Get
Set(ByVal value As Color)
Frame_BackColor = value
Me.Invalidate()
End Set
End Property
Dim Frame_ForeColor As Color = Color.White
<Category("Clock"), DefaultValue("White")> _
Public Property FrameForeColor() As Color
Get
Return Frame_ForeColor
End Get
Set(ByVal value As Color)
Frame_ForeColor = value
Me.Invalidate()
End Set
End Property
Dim Show_Minutes As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property ShowMinutes() As Boolean
Get
Return Show_Minutes
End Get
Set(ByVal value As Boolean)
Show_Minutes = value
Me.Invalidate()
End Set
End Property
ادامه دارد ...کد:
Dim Show_Hours As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property ShowHours() As Boolean
Get
Return Show_Hours
End Get
Set(ByVal value As Boolean)
Show_Hours = value
Me.Invalidate()
End Set
End Property
Dim Second_Hand As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property SecondHand() As Boolean
Get
Return Second_Hand
End Get
Set(ByVal value As Boolean)
Second_Hand = value
Me.Invalidate()
End Set
End Property
<Category("Clock"), DefaultValue("Red")> _
Public Property SecondColor() As Color
Get
Return Second_Color
End Get
Set(ByVal value As Color)
Second_Color = value
PenSec.Color = Second_Color
Me.Invalidate()
End Set
End Property
<Category("Clock"), DefaultValue("Black")> _
Public Property MinuteColor() As Color
Get
Return Minute_Color
End Get
Set(ByVal value As Color)
Minute_Color = value
PenMin.Color = Minute_Color
Me.Invalidate()
End Set
End Property
<Category("Clock"), DefaultValue("Black")> _
Public Property HourColor() As Color
Get
Return Hour_Color
End Get
Set(ByVal value As Color)
Hour_Color = value
PenHour.Color = Hour_Color
Me.Invalidate()
End Set
End Property
Dim Minute_Hand As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property MinuteHand() As Boolean
Get
Return Minute_Hand
End Get
Set(ByVal value As Boolean)
Minute_Hand = value
Me.Invalidate()
End Set
End Property
Dim Hour_Hand As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property HourHand() As Boolean
Get
Return Hour_Hand
End Get
Set(ByVal value As Boolean)
Hour_Hand = value
Me.Invalidate()
End Set
End Property
Dim Show_Digits As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property ShowDigits() As Boolean
Get
Return Show_Digits
End Get
Set(ByVal value As Boolean)
Show_Digits = value
Me.Invalidate()
End Set
End Property
Dim MyText As String = "Sanli © 2008"
<Category("Clock"), DefaultValue("Sanli 2008")> _
Public Property ClockText() As String
Get
Return MyText
End Get
Set(ByVal value As String)
MyText = value.Trim
Me.Invalidate()
End Set
End Property
Dim Digital_Clock As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property DigitalClock() As Boolean
Get
Return Digital_Clock
End Get
Set(ByVal value As Boolean)
Digital_Clock = value
Me.Invalidate()
End Set
End Property
Dim Show_Date As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property ShowDate() As Boolean
Get
Return Show_Date
End Get
Set(ByVal value As Boolean)
Show_Date = value
Me.Invalidate()
End Set
End Property
Dim Frame_Image As Image = Nothing
<Category("Clock"), DefaultValue(GetType(Image), Nothing)> _
Public Property FrameImage() As Image
Get
Return Frame_Image
End Get
Set(ByVal value As Image)
Frame_Image = value
Me.Invalidate()
End Set
End Property
Dim Can_Move As Boolean = True
<Category("Clock"), DefaultValue(True)> _
Public Property CanMove() As Boolean
Get
Return Can_Move
End Get
Set(ByVal value As Boolean)
Can_Move = value
End Set
End Property
#End Region
Private Sub UserControl1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
SetRegion()
FrameWidth = (Me.Width) * (Frame_Thickness / 100)
Timer1.Enabled = Not (Me.DesignMode)
PenSec.EndCap = Drawing2D.LineCap.ArrowAnchor
PenSec.Alignment = Drawing2D.PenAlignment.Center
PenSec.LineJoin = Drawing2D.LineJoin.Round
PenSec.StartCap = Drawing2D.LineCap.RoundAnchor
PenMin.EndCap = Drawing2D.LineCap.ArrowAnchor
PenMin.Alignment = Drawing2D.PenAlignment.Center
PenMin.LineJoin = Drawing2D.LineJoin.Round
PenMin.StartCap = Drawing2D.LineCap.RoundAnchor
PenHour.EndCap = Drawing2D.LineCap.ArrowAnchor
PenHour.Alignment = Drawing2D.PenAlignment.Center
PenHour.LineJoin = Drawing2D.LineJoin.Round
PenHour.StartCap = Drawing2D.LineCap.RoundAnchor
MyFormat.LineAlignment = StringAlignment.Center
MyFormat.Alignment = StringAlignment.Center
MatrixSec.Reset()
MatrixSec.RotateAt((sec) * 6, _
New Point(Me.Width \ 2, Me.Height \ 2))
MatrixMin.Reset()
MatrixMin.RotateAt((sec * 0.1) + (Min * 6), _
New Point(Me.Width \ 2, Me.Height \ 2))
If Hour > 12 Then Hour -= 12
MatrixHour.Reset()
MatrixHour.RotateAt((sec * 0.0083) + (Min * 0.5) + (Hour * 30), _
New Point(Me.Width \ 2, Me.Height \ 2))
RaiseEvent HourChanged()
RaiseEvent MinuteChanged()
RaiseEvent SecondChanged()
End Sub
Private Sub Moving(ByVal e As MouseEventArgs, ByVal Control As Control)
Static OldPosition As New Point(-1, -1)
If Not (e.Button = Nothing) Then
If e.Button = Windows.Forms.MouseButtons.Left Then _
If (OldPosition.X = -1) And (OldPosition.Y = -1) Then OldPosition = New Point(e.X, e.Y)
If e.Y <> OldPosition.Y Then
Control.Top += e.Y - OldPosition.Y 'move Up/Down
End If
If e.X <> OldPosition.X Then
Control.Left += e.X - OldPosition.X 'move Left/Right
End If
End If
Else
OldPosition = New Point(-1, -1)
End If
End Sub
Private Sub UserControl1_MouseMove(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
Me.MouseMove
If Can_Move = True Then Moving(e, Me)
End Sub
ادامه دارد ...کد:
Private Sub UserControl1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.ResetClip()
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
DrawClock(e)
End Sub
Private Sub SetRegion()
'Set Clock Region
Rect.Width = (Me.Width - 1)
Rect.Height = (Me.Height - 1)
Rect.X = 1
Rect.Y = 1
Path.Reset()
Path.FillMode = Drawing2D.FillMode.Winding
If Frame_Mode = F_Mode.QuadrAngular Then
Path.AddRectangle(Rect)
MyRegion = New Region(Path)
Me.Region = MyRegion
Else
Path.AddEllipse(Rect)
MyRegion = New Region(Path)
Me.Region = MyRegion
End If
End Sub
#Region "Drawing Clock"
Private Sub DrawDate(ByVal e As System.Windows.Forms.PaintEventArgs)
Lab1.Font = New Font(Me.Font.Name, ((Me.Height - (FrameWidth \ 2))) * _
(4 / 100), Me.Font.Style, GraphicsUnit.Point)
Lab1.Text = "Jan 83 "
Rect.Width = Lab1.Width
Rect.Height = Lab1.Font.Height
Rect.Y = (Me.Height - Rect.Height) / 2
Rect.X = ((Me.Width * (85 / 100))) - (FrameWidth \ 2) - Rect.Width
e.Graphics.DrawString(MonthName(Now.Month - 1) & " " & Now.Day, _
Lab1.Font, New SolidBrush(Me.ForeColor), Rect,
MyFormat)
e.Graphics.DrawRectangle(New Pen(Me.ForeColor), Rect)
End Sub
Private Sub DigTime(ByVal e As System.Windows.Forms.PaintEventArgs)
Lab1.Font = New Font(Me.Font.Name, ((Me.Height - (FrameWidth \ 2))) * (5 / 100), _
Me.Font.Style, GraphicsUnit.Point)
Lab1.Text = TimeOfDay.TimeOfDay.ToString
Lab1.Text = String.Format(Lab1.Text, "HH:mm:ss")
Rect.Width = Lab1.Width
Rect.Height = Lab1.Height
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = ((Me.Height * (85 / 100))) - (FrameWidth \ 2) - Rect.Height '- H
e.Graphics.DrawString(Lab1.Text, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
End Sub
Private Sub DrawText(ByVal e As System.Windows.Forms.PaintEventArgs)
'Lab1.Font = New Font(Me.Font.Name, Me.Height * (5 / 100), _
Me.Font.Style, GraphicsUnit.Point)
'Lab1.Text = "12"
'Dim H As Integer = Lab1.Font.Height
Lab1.Font = New Font(Me.Font.Name, ((Me.Height - (FrameWidth \ 2))) * (5 / 100), _
Me.Font.Style, GraphicsUnit.Point)
Lab1.Text = MyText
Rect.Width = Lab1.Width
Rect.Height = Lab1.Height
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = ((Me.Height * (15 / 100))) + (FrameWidth / 2) '+ H
e.Graphics.DrawString(MyText, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
End Sub
Private Sub Numbers(ByVal e As System.Windows.Forms.PaintEventArgs)
Lab1.Font = New Font(Me.Font.Name, ((Me.Height - (FrameWidth \ 2))) * (6 / 100), _
Me.Font.Style, GraphicsUnit.Point)
Lab1.Text = "12"
Rect.Width = Lab1.Width
Rect.Height = Lab1.Font.Height
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = ((Me.Height * (15 / 100))) + (FrameWidth \ 2) - Rect.Height + 2
e.Graphics.DrawString(Lab1.Text, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
Lab1.Text = "6"
Rect.Width = Lab1.Width
Rect.Height = Lab1.Font.Height
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = ((Me.Height * (85 / 100))) - 2 - (FrameWidth \ 2)
e.Graphics.DrawString(Lab1.Text, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
Lab1.Text = "3"
Rect.Width = Lab1.Width
Rect.Height = Lab1.Font.Height
Rect.Y = (Me.Height - Rect.Height) / 2
Rect.X = ((Me.Width * (85 / 100))) - (FrameWidth \ 2) + 2 '- Rect.Width
e.Graphics.DrawString(Lab1.Text, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
Lab1.Text = "9"
Rect.Width = Lab1.Width
Rect.Height = Lab1.Font.Height
Rect.Y = (Me.Height - Rect.Height) / 2
Rect.X = ((Me.Width * (15 / 100))) + (FrameWidth \ 2) - Rect.Width
e.Graphics.DrawString(Lab1.Text, Lab1.Font, _
New SolidBrush(Me.ForeColor), Rect, MyFormat)
End Sub
بدلیل حجم بالای سورس کامپوننت ( 6 مگابایت) از آپلود سورس خودداری کردم و به جای آن متن سورس رو در اختیار علاقمندان قرار دادم.کد:
Private Sub FrameOfClock(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim brPenBrush As New System.Drawing.Drawing2D.HatchBrush(HatchStyle, _
Frame_ForeColor, Frame_BackColor)
If Frame_Thickness <= 0 Then
brPenBrush = New System.Drawing.Drawing2D.HatchBrush(HatchStyle, _
Color.Transparent, Color.Transparent)
End If
Dim MyBrushPen As New Pen(brPenBrush)
MyBrushPen.Width = FrameWidth
Rect.Width = Me.Width
Rect.Height = Me.Height
Rect.X = 0
Rect.Y = 0
If Frame_Mode = F_Mode.QuadrAngular Then
e.Graphics.DrawRectangle(MyBrushPen, Rect)
Else
e.Graphics.DrawEllipse(MyBrushPen, Rect)
End If
End Sub
Private Sub ImageOfFrame(ByVal e As System.Windows.Forms.PaintEventArgs)
If Frame_Thickness <= 0 Then Me.FrameOfClock(e) : Exit Sub
Dim ExcludRect As New Rectangle(FrameWidth / 2, FrameWidth / 2, _
Me.Width - FrameWidth, Me.Height - FrameWidth)
Path.Reset()
If Frame_Mode = F_Mode.QuadrAngular Then
Path.AddRectangle(ExcludRect)
Else
Path.AddPie(ExcludRect, 0, 360)
End If
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
Rect.Width = Me.Width + 1
Rect.Height = Me.Height + 1
Rect.X = 0
Rect.Y = 0
e.Graphics.DrawImage(Frame_Image, Rect)
e.Graphics.ResetClip()
End Sub
Private Sub FirstExcluding(ByVal e As System.Windows.Forms.PaintEventArgs)
'Excluding Area
Rect.Width = ((Me.Width - 1) * (90 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (90 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.Reset()
Path.AddPie(Rect, 0, 360)
Rect.Width = ((Me.Width - 1) * (95 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (95 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.AddPie(Rect, 0, 360)
Rect.Width = (Me.Width - 1) + 200
Rect.Height = (Me.Height - 1) + 200
Rect.X = -100
Rect.Y = -100
Path.AddPie(Rect, 0, 360)
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
End Sub
Private Sub NextExcluding(ByVal e As System.Windows.Forms.PaintEventArgs)
'Excluding Area
Rect.Width = ((Me.Width - 1) * (85 / 100)) - FrameWidth
Rect.Height = ((Me.Height - 1) * (85 / 100)) - FrameWidth
Rect.X = (Me.Width - Rect.Width) / 2
Rect.Y = (Me.Height - Rect.Height) / 2
Path.Reset()
Path.AddEllipse(Rect)
MyRegion = New Region(Path)
e.Graphics.ResetClip()
e.Graphics.ExcludeClip(MyRegion)
End Sub
Private Sub HandOfSecond(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه ثانیه شمار
e.Graphics.Transform = MatrixSec
e.Graphics.DrawLine(PenSec, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 30) + (FrameWidth \ 2))
End Sub
Private Sub HandOfMinute(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه دقیقه شمار
e.Graphics.Transform = MatrixMin
e.Graphics.DrawLine(PenMin, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 10) + (FrameWidth \ 2))
End Sub
Private Sub HandOfHour(ByVal e As System.Windows.Forms.PaintEventArgs)
'عقربه ساعت شمار
e.Graphics.Transform = MatrixHour
e.Graphics.DrawLine(PenHour, Me.Width \ 2, Me.Height \ 2, _
Me.Width \ 2, (Me.Height \ 5) + (FrameWidth \ 2))
End Sub
Private Sub DrawClock(ByVal e As System.Windows.Forms.PaintEventArgs)
If Frame_Image Is Nothing Then
FrameOfClock(e)
Else
ImageOfFrame(e)
End If
'Excluding 1
FirstExcluding(e)
'Draw All Minute
Rect.Width = (Me.Width - 1) + 100
Rect.Height = (Me.Height - 1) + 100
Rect.X = -50
Rect.Y = -50
If Show_Minutes = True Then
For i As Integer = 0 To 360 Step 6
e.Graphics.DrawPie(New Pen(Me.ForeColor, Me.Width / 400), Rect, i, 6)
Next
End If
'Bold Hour 1,2,4,5,7,8,10,11
If Show_Hours = True Then
Dim MatrixTemp As New System.Drawing.Drawing2D.Matrix
For i As Integer = 0 To 360 Step 30
If i Mod 90 <> 0 And i > 0 Then
MatrixTemp.RotateAt(30, New Point(Me.Width \ 2, Me.Height \ 2))
e.Graphics.Transform = MatrixTemp
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), (Me.Width \ 2), 0, (Me.Width \ 2), Me.Height)
Else
If i > 0 Then MatrixTemp.RotateAt(30, New Point(Me.Width \ 2, Me.Height \ 2))
End If
Next
MatrixTemp.Dispose()
e.Graphics.Transform = New System.Drawing.Drawing2D.Matrix
End If
'Excluding 1
NextExcluding(e)
'Bold Hour 12 , 3 , 6 , 9
If Show_Hours = True Then
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), _
(Me.Width \ 2), FrameWidth \ 2, (Me.Width \ 2), Me.Height - (FrameWidth \ 2))
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Width / 100), _
(FrameWidth \ 2), Me.Height \ 2, Me.Width - (FrameWidth \ 2), Me.Height \ 2)
End If
e.Graphics.ResetClip()
If Show_Digits = True Then Numbers(e)
DrawText(e)
If Digital_Clock = True Then DigTime(e)
If Show_Date = True Then DrawDate(e)
'Hands
If Hour_Hand = True Then HandOfHour(e)
If Minute_Hand = True Then HandOfMinute(e)
If Second_Hand = True Then HandOfSecond(e)
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
sec = Now.Second
MatrixSec.Reset()
MatrixSec.RotateAt((sec) * 6, New Point(Me.Width \ 2, Me.Height \ 2))
Min = Now.Minute
MatrixMin.Reset()
MatrixMin.RotateAt((sec * 0.1) + (Min * 6), New Point(Me.Width \ 2, Me.Height \ 2))
Hour = Now.Hour
If Hour > 12 Then Hour -= 12
MatrixHour.Reset()
MatrixHour.RotateAt((sec * 0.0083) + (Min * 0.5) + (Hour * 30), _
New Point(Me.Width \ 2, Me.Height \ 2))
Me.Invalidate()
If EventHour <> Now.Hour Then
RaiseEvent HourChanged()
EventHour = Now.Hour
ElseIf EventMin <> Now.Minute Then
RaiseEvent MinuteChanged()
EventMin = Now.Minute
Else
RaiseEvent SecondChanged()
End If
End Sub
Private Sub UserControl1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.SizeChanged
If Me.Width > Me.Height Then
Me.Height = Me.Width
ElseIf Me.Height > Me.Width Then
Me.Width = Me.Height
End If
SetRegion()
FrameWidth = (Me.Width) * (Frame_Thickness / 100)
PenSec.Width = Me.Width / 100
PenMin.Width = Me.Width / 55
PenHour.Width = Me.Width / 35
sec = Now.Second
Min = Now.Minute
Hour = Now.Hour
If Hour > 12 Then Hour -= 12
MatrixSec.Reset()
MatrixSec.RotateAt((sec) * 6, New Point(Me.Width \ 2, Me.Height \ 2))
Min = Now.Minute
MatrixMin.Reset()
MatrixMin.RotateAt((sec * 0.1) + (Min * 6), New Point(Me.Width \ 2, Me.Height \ 2))
MatrixHour.Reset()
MatrixHour.RotateAt((sec * 0.0083) + (Min * 0.5) + (Hour * 30), _
New Point(Me.Width \ 2, Me.Height \ 2))
End Sub
End Class
به تمامی سوالات دوستان در مورد این سورس پاسخ داده خواهد شد.
پایان ساعت آنالوگ.
باز هم به سوالات دوستان پاسخ داده خواهد شد.کد:http://shalineh.parsaspace.com/FarsiCalend.zip
سلام
ایول خیلی با این سورس هات حال دادی
ممنون