(31-05-19, 02:59 AM)ابراهيم ايبو كتب : السلام عليكم ورحمة الله وبركاته
بفضل من الله ورغبة في مني في دخول عالم الغرافيك مع الفيجوال بيسك نت .. بدأت اولى الخطوات وعملت مثال لرسم مستطيل بالاعتماد على احداثيات الماوس وتلوين الاطار والتعبئة بناء على تحديدات كيفية وقد اعتمدت على مخزوني البرمجي مما علمني اياه [b][b]الله [/b]وأهل العلم بدون معرفتي بكلاسات خاصة بالرسم وقد وفقت الى ذلك ولكن ليس كما ارغب وأحب .[/b]
والسؤال الراهن هو كيف اجلب احداثيات الماوس بالنسبة لكونترول وليكن PictureBox مثلا بحيث تبدأ الاحداثيات من الـ location الخاص بـ (PictureBox (0:0 لأن في المثال الاحداثيات تكون لشاشة الكومبيوتر وتحايلت عليها لجلب احداثياتها في الفورم .. اتمنى من الاعضاء الذين لديهم خبرة في مجال الغرافيك فضلا وتكرما القاء نظرة على المثال ..
كما اهيب بكل من عنده روابط او فيديوهات عن الرسم بالفيجوال أن يضعها مشكورا ويجعلها الله في ميزان حسناته ليستفيد منها بقية الاعضاء ممن لهم اهتمام بهذا الجانب من البرمجة
دمتم بكل خير ... رمضان كريم والعيد على الابواب وكل عام وأنتم بخير والى الله أقرب
هذه تعديلات عدلتها بناء على بعض مما في درس لاحد الاعضاء احتفظت بخواتها لي في ملف نصي
Public Class Form1
' احداثيات الماوس في رسم مساحة
' النقطة الاولى
Dim firstPoint As Point
' النقطة الثانية
Dim secondPoint As Point
' اون الرسم
Dim drawColor As Color
' لون التعبئه
Dim fillColor As Color
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' اعدادات اوليه
fillColor = RectangleShape2.FillColor
drawColor = RectangleShape1.BorderColor
End Sub
' اختيار لون الكونتور
Private Sub RectangleShape1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles RectangleShape1.Click
Dim colrd As New ColorDialog()
If colrd.ShowDialog = Windows.Forms.DialogResult.OK Then
drawColor = colrd.Color
RectangleShape1.BorderColor = drawColor
End If
End Sub
' اختيار لون التعبئة
Private Sub RectangleShape2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles RectangleShape2.Click
Dim colrd As New ColorDialog()
If colrd.ShowDialog = Windows.Forms.DialogResult.OK Then
fillColor = colrd.Color
RectangleShape2.FillColor = fillColor
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
PictureBox1.CreateGraphics().Clear(Color.White)
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
' جلب احداثيات ضغطة الماوس الاولى
firstPoint = e.Location
Label1.Text = "x :" & firstPoint.X & " " & "y :" & firstPoint.Y
End If
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
' جلب احداثيات رفع الماوس
secondPoint = e.Location
' جلب احداثيات رسم المستطيل
Dim rect As New Rectangle(firstPoint.X, firstPoint.Y, (secondPoint.X - firstPoint.X), (secondPoint.Y - firstPoint.Y))
Label2.Text = "x :" & secondPoint.X & " " & "y :" & secondPoint.Y
Label3.Text = "Width :" & rect.Width & " " & "Heigh :" & rect.Height
' التعبئه اولا
Dim Sbrush As New SolidBrush(fillColor)
PictureBox1.CreateGraphics().FillRectangle(Sbrush, rect)
' الاطار ثانيا
Dim PLinePen As New Pen(drawColor, Nmr_StrokPen.Value)
PictureBox1.CreateGraphics().DrawRectangle(PLinePen, rect)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
نست ان اذكر ان تضيف picturebox وتضع له اطار في الخصائص fixedsingle وذلك قبل نسخ الكود
