تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تحريك الادوات بالفأرة وقت التشغيل
#1
[SIZE=5]السلام عليكم ورحمة الله وبركاته

=======================




هذه اكواد تمكنك من تحريك الادوات بالفأرة على النموذج وقت التشغيل كأنك تحركها فى وقت التصميم






أولا : للأمانة هذه الاكواد ليست من تصميمي وانما هى منقولة من احد المواقع


ثانيا : قم بانشاء مشروع جديد من النوع Windows Application وضع عليه Button


ثالثا : قم بأضافة Class وسمها ClsCapture


ثالثا : الصق داخل هذه الفئة الاكواد التالية
[/SIZE]
كود :
[align=left][b][SIZE=2][FONT=times new roman]
[/FONT][/SIZE][/b][SIZE=2][FONT=times new roman][FONT=tahoma]
#Region "Global Vars"


    Dim WithEvents dad As Form
    Dim WithEvents dd As Control
    Dim WithEvents Btn_exit As New Button
    Dim WithEvents Btn_Min As New Button
    Dim bCaptureMe As Boolean
    Dim pLocation As New Point


#End Region


    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'Handles dad.MouseDown, dd.MouseDown
        Try
            bCaptureMe = True
            pLocation = e.Location
            sender.BringToFront()
        Catch
        End Try
    End Sub


    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'Handles dad.MouseMove, dd.MouseMove
        Try
            If bCaptureMe Then
                If dd Is Nothing AndAlso dad.Cursor <> Cursors.SizeNESW _
                AndAlso dad.Cursor <> Cursors.SizeNWSE _
                AndAlso dad.Cursor <> Cursors.SizeNS _
                AndAlso dad.Cursor <> Cursors.SizeWE Then
                    dad.Location = New Point(dad.Location.X - pLocation.X + e.X, dad.Location.Y - pLocation.Y + e.Y)


                ElseIf dd.Cursor <> Cursors.SizeNESW _
                AndAlso dd.Cursor <> Cursors.SizeNWSE _
                AndAlso dd.Cursor <> Cursors.SizeNS _
                AndAlso dd.Cursor <> Cursors.SizeWE Then
                    dd.Location = New Point(dd.Location.X - pLocation.X + e.X, dd.Location.Y - pLocation.Y + e.Y)
                End If


            End If
        Catch
        End Try
    End Sub


    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dad.MouseUp, dd.MouseUp
        Try
            bCaptureMe = False
        Catch
        End Try
    End Sub


    Public Sub New(ByVal Frm As Form, ByVal MakeRound As Boolean)
        dad = Frm
        If MakeRound Then
            RoundShape()
            AddHandler Btn_exit.Click, AddressOf Close_Click
            AddHandler Btn_Min.Click, AddressOf Min_Click
        End If
        AddHandler dad.MouseDown, AddressOf Form1_MouseDown
        AddHandler dad.MouseUp, AddressOf Form1_MouseUp
        AddHandler dad.MouseMove, AddressOf Form1_MouseMove
    End Sub


    Public Sub New(ByVal pnl As Control)
        dd = pnl
        AddHandler dd.MouseDown, AddressOf Form1_MouseDown
        AddHandler dd.MouseUp, AddressOf Form1_MouseUp
        AddHandler dd.MouseMove, AddressOf Form1_MouseMove
    End Sub


    Public Sub RoundShape()
        Try
            dad.FormBorderStyle = FormBorderStyle.None
            Dim gr = New System.Drawing.Drawing2D.GraphicsPath()
            gr.AddPie(0, 0, 40, 40, 180, 90)
            gr.AddPie(dad.Width - 40, 0, 40, 40, 270, 90)
            gr.AddPie(0, dad.Height - 40, 40, 40, 90, 90)
            gr.AddPie(dad.Width - 40, dad.Height - 40, 40, 40, 0, 90)


            gr.AddRectangle(New Drawing.Rectangle(20, 0, dad.Width - 40, dad.Height))
            gr.AddRectangle(New Drawing.Rectangle(0, 20, 20, dad.Height - 40))
            gr.AddRectangle(New Drawing.Rectangle(dad.Width - 20, 20, 20, dad.Height - 40))


            dad.Region = New Region(gr)




            Btn_exit.Cursor = System.Windows.Forms.Cursors.Hand
            Btn_exit.FlatAppearance.BorderSize = 0
            Btn_exit.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(128, Byte), Integer), CType(CType(0, Byte), Integer))
            Btn_exit.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
            Btn_exit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
            Btn_exit.Location = New System.Drawing.Point(dad.Width - 18, 0)
            Btn_exit.Name = "BtnClose"
            Btn_exit.Size = New System.Drawing.Size(18, 21)
            Btn_exit.TabIndex = 6
            Btn_exit.Text = "X"
            Btn_exit.UseVisualStyleBackColor = True
            Btn_exit.BringToFront()


            Btn_Min.Cursor = System.Windows.Forms.Cursors.Hand
            Btn_Min.FlatAppearance.BorderSize = 0
            Btn_Min.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(128, Byte), Integer), CType(CType(0, Byte), Integer))
            Btn_Min.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
            Btn_Min.FlatStyle = System.Windows.Forms.FlatStyle.Flat
            Btn_Min.Location = New System.Drawing.Point(dad.Width - 36, 0)
            Btn_Min.Name = "BtnClose"
            Btn_Min.Size = New System.Drawing.Size(18, 21)
            Btn_Min.TabIndex = 6
            Btn_Min.Text = "_"
            Btn_Min.UseVisualStyleBackColor = True
            Btn_Min.BringToFront()


            dad.Controls.Add(Btn_exit)
            dad.Controls.Add(Btn_Min)
        Catch
        End Try
    End Sub


    Private Sub Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CType(sender, Button).FindForm.Close()
    End Sub


    Private Sub Min_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CType(sender, Button).FindForm.WindowState = FormWindowState.Minimized
    End Sub


    Public Shared Sub CaptureAllCtrls(ByVal fr As Control)
        For Each cnt As Control In fr.Controls
            If TypeOf cnt Is Panel Then
                CaptureAllCtrls(cnt)
            Else
                ClsCapture.CaptureMe(cnt)
            End If
        Next
    End Sub


    Public Shared Sub CaptureMe(ByVal frm As Form, Optional ByVal MakeMeRound As Boolean = False)
        Dim cc As New ClsCapture(frm, MakeMeRound)
    End Sub


    Public Shared Sub CaptureMe(ByVal pnl As Control)
        Dim cc As New ClsCapture(pnl)
    End Sub
[/FONT][/FONT][/SIZE][b][SIZE=2][FONT=times new roman]
[/FONT][/SIZE][/b][/align]
رابعا : اذهب الى النموذج وفى الحدث Form1_Load اكتب هذا الكود

كود :
[align=left][FONT=tahoma][SIZE=2]ClsCapture.CaptureMe(Button1)[/SIZE][/FONT][/align]


خامسا : شغل البرنامج وجرب تحريك الـ Button


اذا اردت تحريك كل الادوات اكتب التالى

كود :
[align=left][FONT=tahoma][SIZE=2]ClsCapture.CaptureMe(me)[/SIZE][/FONT][/align]
قم بعلم ولا تطلب به بدلا             فالناس موتى وأهل العلم احياء

الامام على رضوان الله عليه
الرد }}}
تم الشكر بواسطة:
#2
شكراً جزيلا لك اخي الكريم Cool
الرد }}}
تم الشكر بواسطة:
#3
تسلم الله يعطيك العافيه

تم التجربة والكود شغال
100 %


Big Grin
<---------------------------------------------------------------->

الرد }}}
تم الشكر بواسطة:
#4
شكرا لك الموضوع يستاهل النقل
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
Video [درس فيديو] تقارير الكريستال ريبورت وتغيير مسار الصور أثناء التشغيل رمضان272 0 1,610 28-03-22, 03:18 AM
آخر رد: رمضان272
  الادوات الوهمية محمود صالح 1 2,000 30-12-17, 05:04 PM
آخر رد: حريف برمجة
  [VB.NET] تحريك الادوات بالماوس وقت التشغيل Ahmed_online 4 3,426 26-11-15, 02:28 PM
آخر رد: eldmasy11
  من المنتدى القديم - تحريك الفورم من اي مكان ( للاخ omar2205 ) المبرمج علي نوري 2 2,945 16-08-15, 05:09 PM
آخر رد: otman_bel
  نبضه 2 - التشغيل العشوائي لملفات صوتيه RaggiTech 0 1,904 05-10-12, 04:14 AM
آخر رد: RaggiTech
  تعلم أضافة الأدوات على الفورم وقت التشغيل وإضافة أحداث الضغط وما شايه لها RaggiTech 0 2,086 03-10-12, 09:29 AM
آخر رد: RaggiTech
  تخزين ملف ما ضمن Exe البرنامج أثناء التطوير واستعادته أثناء التشغيل RaggiTech 1 2,155 03-10-12, 08:14 AM
آخر رد: RaggiTech
  تحريك النافذة وهي في وضعية none ! RaggiTech 0 2,153 03-10-12, 07:50 AM
آخر رد: RaggiTech
  تحريك الفورم من اى مكان فيها -) RaggiTech 0 4,954 03-10-12, 07:43 AM
آخر رد: RaggiTech
  تحريك الادوات بالفأرة على النموذج وقت التشغيل RaggiTech 0 1,961 03-10-12, 07:42 AM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم