RE: ممكن رسم سهم بهذا الكود - abdalamask - 24-04-17
صح
اريد ان يكون السهم مثل نفس شكل و الوان الياتون الدائري
RE: ممكن رسم سهم بهذا الكود - silverlight - 25-04-17
كود الباتون مربع
و سأضع لك كود السهم لاحقا
PHP كود :
Imports System.Drawing.Drawing2D Imports System.ComponentModel
Public Class LedSingleControlٌُRect Inherits Control
#Region "Declare variables"
Private _OnColor As Color = Color.Lime
Private _OffColor As Color = Color.DarkGray #End Region
#Region "Contructors"
#End Region #Region "Properties"
<Category("HMI Properties")> Private _Value As Boolean = True
Public Property Value() As Boolean Get Return _Value End Get
Set(ByVal value As Boolean) _Value = value
Me.Invalidate() End Set End Property <Category("HMI Properties")> Public Property OnColor() As Color Get Return _OnColor End Get
Set(ByVal value As Color) _OnColor = value Me.Refresh() End Set End Property <Category("HMI Properties")> Public Property OffColor() As Color Get Return _OffColor End Get
Set(ByVal value As Color) _OffColor = value Me.Refresh() End Set End Property #End Region #Region "Methods & Events"
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) e.Graphics.SmoothingMode = SmoothingMode.AntiAlias Dim g As Graphics = e.Graphics Dim pointF As New PointF(CSng(Me.Width) / 2.0F, CSng(Me.Height) / 2.0F) Dim num1 As Single = Math.Min(pointF.X, pointF.Y) Dim num2 As Single = CSng(CDbl(num1) * 65.0 / 100.0) Dim num3 As Single = CSng(CDbl(num1) * 55.0 / 100.0) Dim num4 As Single = CSng(CDbl(num1) * 45.0 / 100.0) Dim _Brush As Brush = CType(New LinearGradientBrush(New Point(CInt(Math.Truncate(CDbl(pointF.X) - CDbl(num2))), CInt(Math.Truncate(CDbl(pointF.Y) - CDbl(num2)))), New Point(CInt(Math.Truncate(CDbl(pointF.X) + CDbl(num2))), CInt(Math.Truncate(CDbl(pointF.Y) + CDbl(num2)))), Color.WhiteSmoke, SystemColors.ControlDarkDark), Brush) g.FillRectangle(_Brush, pointF.X - num2, pointF.Y - num2, 2.0F * num2, 2.0F * num2) _Brush.Dispose() If Me._Value Then Dim path As New GraphicsPath() Dim r As Rectangle = New Rectangle(pointF.X - num1, pointF.Y - num1, num1 * 2.0F, num1 * 2.0F) path.AddRectangle(r) Dim pathGradientBrush As New PathGradientBrush(path) pathGradientBrush.CenterColor = Color.FromArgb(150, CInt(Me.OnColor.R), CInt(Me.OnColor.G), CInt(Me.OnColor.B)) Dim colorArray() As Color = {Color.FromArgb(1, CInt(Me.OnColor.R), CInt(Me.OnColor.G), CInt(Me.OnColor.B))} pathGradientBrush.SurroundColors = colorArray g.FillRectangle(CType(pathGradientBrush, Brush), pointF.X - num1, pointF.Y - num1, num1 * 2.0F, num1 * 2.0F) path.Dispose() pathGradientBrush.Dispose() End If Dim brush2 As Brush = CType(New LinearGradientBrush(New Point(CInt(Math.Truncate(CDbl(pointF.X) - CDbl(num3))), CInt(Math.Truncate(CDbl(pointF.Y) - CDbl(num3)))), New Point(CInt(Math.Truncate(CDbl(pointF.X) + CDbl(num3))), CInt(Math.Truncate(CDbl(pointF.Y) + CDbl(num2)))), SystemColors.ControlDarkDark, Color.WhiteSmoke), Brush) g.FillRectangle(brush2, pointF.X - num3, pointF.Y - num3, 2.0F * num3, 2.0F * num3) _Brush.Dispose() Dim gp As New GraphicsPath() Dim r1 As Rectangle = New Rectangle(pointF.X - num4, pointF.Y - num4, 2.0F * num4, 2.0F * num4) gp.AddRectangle(r1) If Me._Value Then Dim pathGradientBrush As New PathGradientBrush(gp) pathGradientBrush.CenterColor = Color.WhiteSmoke Dim colorArray() As Color = {Me.OnColor} pathGradientBrush.SurroundColors = colorArray pathGradientBrush.CenterPoint = New PointF(pointF.X - num4 / 2.0F, pointF.Y - num4 / 2.0F) g.FillRectangle(CType(pathGradientBrush, Brush), pointF.X - num4, pointF.Y - num4, 2.0F * num4, 2.0F * num4) pathGradientBrush.Dispose() Else Dim pathGradientBrush As New PathGradientBrush(gp) pathGradientBrush.CenterColor = Color.WhiteSmoke Dim colorArray() As Color = {Me.OffColor} pathGradientBrush.SurroundColors = colorArray pathGradientBrush.CenterPoint = New PointF(pointF.X - num4 / 2.0F, pointF.Y - num4 / 2.0F) g.FillRectangle(CType(pathGradientBrush, Brush), pointF.X - num4, pointF.Y - num4, 2.0F * num4, 2.0F * num4) pathGradientBrush.Dispose() End If gp.Dispose() End Sub
Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs) MyBase.OnSizeChanged(e) Dim num As Single = CSng(Math.Min(Me.Width, Me.Height)) If CDbl(num) < 20.0 Then num = 20.0F End If Me.Width = CInt(Math.Truncate(num)) Me.Height = CInt(Math.Truncate(num)) Dim path As New GraphicsPath() Dim r As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height) path.AddRectangle(r) Me.Region = New Region(path) End Sub
#End Region
End Class
RE: ممكن رسم سهم بهذا الكود - abdalamask - 25-04-17
تمام
معاك
RE: ممكن رسم سهم بهذا الكود - silverlight - 26-04-17
PHP كود :
Imports System.Drawing.Drawing2D Imports System.ComponentModel
Public Class LedSingleControlArrow Inherits Control
#Region "Declare variables" Private _OnColor As Color = Color.Lime Private _OffColor As Color = Color.DarkGray #End Region
#Region "Contructors"
#End Region #Region "Properties"
<Category("HMI Properties")> Private _Value As Boolean = True
Public Property Value() As Boolean Get Return _Value End Get
Set(ByVal value As Boolean) _Value = value
Me.Invalidate() End Set End Property <Category("HMI Properties")> Public Property OnColor() As Color Get Return _OnColor End Get
Set(ByVal value As Color) _OnColor = value Me.Refresh() End Set End Property <Category("HMI Properties")> Public Property OffColor() As Color Get Return _OffColor End Get
Set(ByVal value As Color) _OffColor = value Me.Refresh() End Set End Property #End Region
#Region "Methods & Events"
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) e.Graphics.SmoothingMode = SmoothingMode.AntiAlias Dim g As Graphics = e.Graphics Dim pointF As New PointF(CSng(Me.Width) / 2.0F, CSng(Me.Height) / 2.0F) Dim num1 As Single = Math.Min(pointF.X, pointF.Y) Dim num2 As Single = CSng(CDbl(num1) * 65.0 / 100.0) Dim num3 As Single = CSng(CDbl(num1) * 55.0 / 100.0) Dim num4 As Single = CSng(CDbl(num1) * 45.0 / 100.0) Dim _Brush As Brush = CType(New LinearGradientBrush(New Point(CInt(Math.Truncate(CDbl(pointF.X) - CDbl(num2))), CInt(Math.Truncate(CDbl(pointF.Y) - CDbl(num2)))), New Point(CInt(Math.Truncate(CDbl(pointF.X) + CDbl(num2))), CInt(Math.Truncate(CDbl(pointF.Y) + CDbl(num2)))), Color.WhiteSmoke, SystemColors.ControlDarkDark), Brush) Dim bottomLayerRect As Rectangle = New Rectangle(pointF.X - num2, pointF.Y - num2, 2.0F * num2, 2.0F * num2) Dim bottomlayerPath As GraphicsPath = New GraphicsPath() Me.GetArrowPath(bottomlayerPath, bottomLayerRect, Directions.East) g.FillPath(_Brush, bottomlayerPath) _Brush.Dispose() If Me._Value Then Dim path As New GraphicsPath() Dim r As Rectangle = New Rectangle(pointF.X - num1, pointF.Y - num1, num1 * 2.0F, num1 * 2.0F) 'Dim p2 As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath GetArrowPath(path, r, Directions.East)
Dim pathGradientBrush As New PathGradientBrush(path) pathGradientBrush.CenterColor = Color.FromArgb(150, CInt(Me.OnColor.R), CInt(Me.OnColor.G), CInt(Me.OnColor.B)) Dim colorArray() As Color = {Color.FromArgb(1, CInt(Me.OnColor.R), CInt(Me.OnColor.G), CInt(Me.OnColor.B))} pathGradientBrush.SurroundColors = colorArray
g.FillPath(CType(pathGradientBrush, Brush), path) path.Dispose() pathGradientBrush.Dispose()
End If Dim brush2 As Brush = CType(New LinearGradientBrush(New Point(CInt(Math.Truncate(CDbl(pointF.X) - CDbl(num3))), CInt(Math.Truncate(CDbl(pointF.Y) - CDbl(num3)))), New Point(CInt(Math.Truncate(CDbl(pointF.X) + CDbl(num3))), CInt(Math.Truncate(CDbl(pointF.Y) + CDbl(num2)))), SystemColors.ControlDarkDark, Color.WhiteSmoke), Brush) g.FillRectangle(brush2, pointF.X - num3, pointF.Y - num3, 2.0F * num3, 2.0F * num3) _Brush.Dispose() Dim gp As New GraphicsPath() Dim r1 As Rectangle = New Rectangle(pointF.X - num4, pointF.Y - num4, 2.0F * num4, 2.0F * num4) GetArrowPath(gp, r1, Directions.East)
If Me._Value Then Dim pathGradientBrush As New PathGradientBrush(gp) pathGradientBrush.CenterColor = Color.WhiteSmoke Dim colorArray() As Color = {Me.OnColor} pathGradientBrush.SurroundColors = colorArray pathGradientBrush.CenterPoint = New PointF(pointF.X - num4 / 2.0F, pointF.Y - num4 / 2.0F) g.FillPath(CType(pathGradientBrush, Brush), gp) pathGradientBrush.Dispose() Else Dim pathGradientBrush As New PathGradientBrush(gp) pathGradientBrush.CenterColor = Color.WhiteSmoke Dim colorArray() As Color = {Me.OffColor} pathGradientBrush.SurroundColors = colorArray pathGradientBrush.CenterPoint = New PointF(pointF.X - num4 / 2.0F, pointF.Y - num4 / 2.0F) g.FillPath(CType(pathGradientBrush, Brush), gp) pathGradientBrush.Dispose() End If gp.Dispose() End Sub
Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs) MyBase.OnSizeChanged(e) Dim num As Single = CSng(Math.Min(Me.Width, Me.Height)) If CDbl(num) < 20.0 Then num = 20.0F End If Me.Width = CInt(Math.Truncate(num)) Me.Height = CInt(Math.Truncate(num)) Dim path As New GraphicsPath() Dim r As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height) GetArrowPath(path, r, Directions.East) Me.Region = New Region(path) End Sub
Private Sub GetArrowPath(path As Drawing2D.GraphicsPath, rect As Rectangle, direction As Directions) Dim rectF As RectangleF = RectangleF.Inflate(rect, -4.0F, -4.0F) Dim x As Single = (rectF.X + rectF.Width / 2.0F) Dim y As Single = (rectF.Y + rectF.Height / 2.0F) path.StartFigure() path.AddLines(New PointF() { New PointF(x, rectF.Top), New PointF(rectF.Right, (rectF.Y + rectF.Height * 0.7F)), New PointF((rectF.X + rectF.Width * 0.7F), (rectF.Y + rectF.Height * 0.7F)), New PointF((rectF.X + rectF.Width * 0.7F), rectF.Bottom), New PointF((rectF.X + rectF.Width * 0.3F), rectF.Bottom), New PointF((rectF.X + rectF.Width * 0.3F), (rectF.Y + rectF.Height * 0.7F)), New PointF(rectF.Left, (rectF.Y + rectF.Height * 0.7F))}) path.CloseAllFigures() Dim matrix As Drawing2D.Matrix = New Drawing2D.Matrix() Select Case direction Case Directions.East matrix.RotateAt(90.0F, New PointF(x, y)) Case Directions.South matrix.RotateAt(180.0F, New PointF(x, y)) Case Directions.West matrix.RotateAt(270.0F, New PointF(x, y)) End Select path.Transform(matrix) End Sub
Public Enum Directions North East South West End Enum
#End Region
End Class
انا لم أعدل في الكود الأصلي كثيرا
لكن الكود يحتاج اعادة صياغة بالكامل
خاصة انك في الحدث Resize تقوم بضبط Region حتي يكون طول الكونترول مساويا لعرض الكونترول
أيضا انت كتبت الكود لتتم عملية الرسم علي هيئة طبقات Layers
لأنك وعلي ما يبدو تريد الاختفاظ بالشكل العام للكونترول من حيث Glow و الألوان
أنصحك تدرس الكلاس Blend سوف يوفر عليك صداع كثير جدا
ايضا أنصحك ان لا تقوم بضبط Region فقط تقوم بعمل Invalidate للكونترول في حالة Resize للكونترول و هذا سيعطيك امكانية ان تتحكم انت بأبعاد الكونترول في مرحلة التصميم
RE: ممكن رسم سهم بهذا الكود - abdalamask - 27-04-17
شكرا على المحاولة
كيف ارسم السهم فى WPF
RE: ممكن رسم سهم بهذا الكود - abdalamask - 02-05-17
وشكرا على مساعدتكم ولا تنزعج منى
وهذة المكتبة المنشودة للافادة
[url= https://cdn.fbsbx.com/v/t59.2708-21/1819...9403A&dl=1[/url]
شكرا لكم
RE: ممكن رسم سهم بهذا الكود - silverlight - 02-05-17
اللينك الذي وضعته للمكتبه لا يعمل
برجاء تعديل اللينك أور فع المكتبة نفسها
|