السلام عليكم
اريد ان ارسم مجموعة من النقاط بالفجوال كالتالي
For i = 1 To 10
Points = New PointF() {New PointF(i * 5, i * 3)}
Plot.DataPoints = New PointF() {Add(Points(i).X, Points(i).Y)}
Next
لكي نرسم نقاط عند الضغط بالزر الايسر للفارة على الفورم (كانك تكتب بالقلم)
استخدم الكود التالي:
كود :
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim g As Graphics = CreateGraphics()
Dim e1 As New PaintEventArgs(g, New Rectangle)
AddLinesExample(e1, e.Location)
End If
End Sub
Dim myPointArray As New List(Of Point)
Public Sub AddLinesExample(ByVal e As PaintEventArgs, epos As Point)
'Create a symetrical triangle using an array of points.
myPointArray.Add(New Point(epos))
Dim myPath As New GraphicsPath
myPath.AddLines(myPointArray.ToArray)
' Draw the path to the screen.
Dim myPen As New Pen(Color.Black, 2)
e.Graphics.DrawPath(myPen, myPath)
End Sub
End Class
(15-08-22, 08:22 PM)شكرامعاند الحظ كتب : [ -> ]لكي نرسم نقاط عند الضغط بالزر الايسر للفارة على الفورم (كانك تكتب بالقلم)
استخدم الكود التالي:
كود :
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim g As Graphics = CreateGraphics()
Dim e1 As New PaintEventArgs(g, New Rectangle)
AddLinesExample(e1, e.Location)
End If
End Sub
Dim myPointArray As New List(Of Point)
Public Sub AddLinesExample(ByVal e As PaintEventArgs, epos As Point)
'Create a symetrical triangle using an array of points.
myPointArray.Add(New Point(epos))
Dim myPath As New GraphicsPath
myPath.AddLines(myPointArray.ToArray)
' Draw the path to the screen.
Dim myPen As New Pen(Color.Black, 2)
e.Graphics.DrawPath(myPen, myPath)
End Sub
End Class
لكنني اريد رسمها بلاحداثيات
لا مشكلة يا اخي هذا الكود ليس حصرا على الحدث MouseMove يمكنك استخدامه اينما تريد
ولتتوضيح اكثر ، لكي ترسم تحتاج اولا الى استيراد فضاء الاسماء System.Drawing
باستخدام هذا الكود
كود :
Imports System.Drawing.Drawing2D
ثم تحتاج الى محرك رسوميات Graphic لانه المسؤول عن انشاء الرسومات
ويمكنك اضافته الى اسطر الكود كالاتي
كود :
Dim gr As Graphics= CreateGraphics()
ثم في حالتك التي تريدها وهي رسم نقاط تحتاج الى مسار رسومات Graphics.Path وهو المسؤول عن حفظ
النقاط التي تريد رسمها مع احداثياتها ويتم الاعلان عنه كالتالي
كود :
Dim myPath As New GraphicsPath
الان بقي ان تعلن عن مصفوفة نقاط لكي تحفظ فيها معلومات واحداثيات النقاط
اعلن عنها كالتالي
كود :
Dim myPointArray As New List(Of Point)
الان بقي ان تعبىء مصفوفة النقاط بالنقاط
انا استخدمت احداثيات مؤشر الفارة عندما تتحرك على النافذة وقمت بتمريرها على التوالي الى
myPath
هنا انت تحتاج الى تعبئة مصفوفة النقاط بالطريقة التي تريدها وبعد ان تكمل تعبئة كل النقاط التي تريدها اطلب من محرك الرسومات
ان ينفذ الرسم (الكود)
كود :
Dim myPen As New Pen(Color.Black, 2)
e.Graphics.DrawPath(myPen, myPath)
هذا كل المطلوب لرسم نقاط بالطريقة التي ذكرتها