الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحريك الصورة

بدأه mmsalman87 في 8 يونيو 2009 · 10 رد · 734 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

اريد تحريك الصورة على الفورم بالماوس داخل الفورم وان اراها اثناء التحريك وشكرا

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

هل هذا هو المطلوب؟

Public Class Form1

	Dim cx, cy As Integer
	Dim moving As Boolean

	Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		If e.Button = Windows.Forms.MouseButtons.Left Then
			cx = e.X
			cy = e.Y
			moving = True
		End If
	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		If moving Then
			Me.PictureBox1.Left += (e.X - cx)
			Me.PictureBox1.Top += (e.Y - cy)
		End If
	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		moving = False
	End Sub
End Class

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#3

الكود تمام وشغال ومشكووووووور

ولكن اريد عندما تصل الصورة الى مكان معين ولنفرض panel

اريدها ان تسقط فيها ويتحرر الماوس منها يعني زي كانها drag and drop

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

#4

لم أفهم المطلوب بالتحديد

عموما إذا كان المطلوب هو كيفية عمل Drag-Drop فقد يفيدك هذا الموضوع

/index.php?showtopic=196311

أما بالنسبة للذى فهمته من السؤال فهذا هو الكود ولا أعلم إذا كان هو المطلوب أم لا

Public Class Form1

	Dim cx, cy As Integer
	Dim moving As Boolean

	Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		If e.Button = Windows.Forms.MouseButtons.Left Then
			cx = e.X
			cy = e.Y
			moving = True
		End If
	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		If moving Then
			Me.PictureBox1.Left += (e.X - cx)
			Me.PictureBox1.Top += (e.Y - cy)
			If Me.PictureBox1.Left >= Me.Panel1.Left AndAlso _
			Me.PictureBox1.Left <= Me.Panel1.Left + Me.Panel1.Width AndAlso _
			Me.PictureBox1.Top >= Me.Panel1.Top AndAlso _
			Me.PictureBox1.Top <= Me.Panel1.Top + Me.Panel1.Height Then
				Me.PictureBox1.Parent = Panel1
				Me.PictureBox1.Location = New Point(0, 0)
				moving = False
				Return
			End If
		End If
	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		moving = False
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Me.PictureBox1.BringToFront()
	End Sub
End Class

أرجو إبلاغى إذا كان هذا هو المطلوب أم لا :blink:

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#5

الكود تمام وشغال 100% ولكن انا عندي اكتر من panel لنفرض عندي اكتر من صورة واريد كل صورة ان يضعها المستخدم في ايا panel هو يريد ما الحل ؟

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

#6

هل المطلوب شئ كهذا ؟

Public Class Form1

	Dim cx, cy As Integer
	Dim moving As Boolean

	Private Sub OnPicMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown
		If e.Button = Windows.Forms.MouseButtons.Left Then
			cx = e.X
			cy = e.Y
			moving = True
		End If
	End Sub

	Private Sub CheckParent(ByVal pic As PictureBox)
		For Each ctrl As Control In Me.Controls
			If TypeOf ctrl Is Panel Then
				If pic.Left >= ctrl.Left AndAlso _
				pic.Left <= ctrl.Left + ctrl.Width AndAlso _
				pic.Top >= ctrl.Top AndAlso _
				pic.Top <= ctrl.Top + ctrl.Height Then
					pic.Parent = ctrl
					pic.Location = New Point(0, 0)
					moving = False
					Return
				End If
			End If
		Next
	End Sub

	Private Sub OnPicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove, PictureBox2.MouseMove
		If moving Then
			Dim pic As PictureBox = CType(sender, PictureBox)
			pic.Left += (e.X - cx)
			pic.Top += (e.Y - cy)

			CheckParent(pic)
		End If
	End Sub

	Private Sub OnPicMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp, PictureBox2.MouseUp
		moving = False
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Me.PictureBox1.BringToFront()
	End Sub
End Class

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#7

اخي الكريم مشكور جدا والكود اشتغل بدون مشاكل ولكن لووووووو تعطيني خدمة اخوية كمان بكون ممنونك

اريد مجرد ما دخل جزء من الصورة في ال panel ان يدخلها البرنامج مباشرة على ال panel

يعني مش شرط ان ادخل الصورة كاملة داخلها حتى يقبلها ويسقطها من الماوس

اتمنى ان تكون وصلت الفكرة

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

#8

غير الكود إلى هذا الشكل

Public Class Form1

	Dim cx, cy As Integer
	Dim moving As Boolean

	Private Sub OnPicMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown
		If e.Button = Windows.Forms.MouseButtons.Left Then
			cx = e.X
			cy = e.Y
			moving = True
		End If
	End Sub

	Private Sub CheckParent(ByVal pic As PictureBox)
		For Each ctrl As Control In Me.Controls
			If TypeOf ctrl Is Panel Then
				If ctrl.Bounds.IntersectsWith(pic.Bounds) Then
					pic.Parent = ctrl
					pic.Location = New Point(0, 0)
					moving = False
					Return
				End If
			End If
		Next
	End Sub

	Private Sub OnPicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove, PictureBox2.MouseMove
		If moving Then
			Dim pic As PictureBox = CType(sender, PictureBox)
			pic.Left += (e.X - cx)
			pic.Top += (e.Y - cy)

			CheckParent(pic)
		End If
	End Sub

	Private Sub OnPicMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp, PictureBox2.MouseUp
		moving = False
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Me.PictureBox1.BringToFront()
	End Sub
End Class

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#9

اخي الكريم نفس الشيء لم يختلف اي شيء

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

#10
mmsalman87 كتب:
اخي الكريم نفس الشيء لم يختلف اي شيء

الكود يعمل معى بطريقة جيدة كما طلبت ,, إذا كنت تواجه مشكلة فقم بإرفاق المشروع ليتم مراجعة الكود

تم تعديل هذه المشاركة بواسطة GHOST2010 في 11 يونيو 2009 في 07:39

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#11

اخي الكريم هذا هو الكود كاملا كما في الفورم

Public Class Form1


    Dim cx, cy As Integer
    Dim moving As Boolean

    Private Sub OnPicMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles img1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            cx = e.X
            cy = e.Y
            moving = True
        End If
    End Sub

    Private Sub CheckParent(ByVal pic As PictureBox)
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is Panel Then
                If ctrl.Bounds.IntersectsWith(pic.Bounds) Then
                    pic.Parent = ctrl
                    pic.Location = New Point(0, 0)
                    moving = False
                    Return
                End If
            End If
        Next
    End Sub

    Private Sub OnPicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles img1.MouseMove
        If moving Then
            Dim pic As PictureBox = CType(sender, PictureBox)
            pic.Left += (e.X - cx)
            pic.Top += (e.Y - cy)

            CheckParent(pic)
        End If
    End Sub

    Private Sub OnPicMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles img1.MouseUp
        moving = False
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.img1.BringToFront()
    End Sub
End Class

Maher Salman

Senior Oracle Developer

Oracle Certified Professional

Kuwait

اللهم إني أعوذ بك من الهم والغم والحزن،

وأعوذ بك من العجز والكسل والفشل،

وأعوذ بك من الجبن والبخل،

وأعوذ بك من الكفر والفقر،

وأعوذ بك من غلبة الدين وقهر الرجال

مواضيع مشابهة