تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[تم الحل] كيف اخلي هاندلس ل Button انشاتة بكود
#1
Dim Btnx As New Button

Btnx.Name = "Btnx1"


عندي هذا البتن

اريد لما اضغط عليه يغير اسم الفورم
الرد }}}
تم الشكر بواسطة: bidaya , bidaya
#2
(05-02-20, 11:24 AM)Sorax كتب : Dim Btnx As New Button

Btnx.Name = "Btnx1"


عندي هذا البتن

اريد لما اضغط عليه يغير اسم الفورم

تفظل


كود :
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Dim pt As Point = New Point(10, 10)
       For i As Integer = 0 To 3
           Dim Btnx As Button = New Button
           With Btnx
               Btnx.Location = pt
               Btnx.Text = "Btnx" & (i + 1).ToString
               Btnx.Cursor = Cursors.Hand
               Btnx.Size = New System.Drawing.Size(92, 25)
               ' إضبط خصائص الباتون كيفما شئت
           End With
           ' هنا يتم ضبط مكان كل باتون
           pt.X += Btnx.Height + 95
           Me.Controls.Add(Btnx)
       Next
       ' هنا نضيف الحدث لكل باتون

       For Each b As Button In Me.Controls.OfType(Of Button)()
           AddHandler b.Click, AddressOf Btnx_Click
       Next
   End Sub
   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Text
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"


           Case "Btnx3"


           Case "Btnx4"
               Close()
         



       End Select

   End Sub
الرد }}}
تم الشكر بواسطة: SnTnt , Sorax , asemshahen5
#3
شكرا بس بعد التعديل بعد ميشتغل الهاندلس

كود :
Public Class Form2


   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Dim pt As Point = New Point(10, 10)
       For i As Integer = 0 To 3
           Dim Btnx As Button = New Button
           With Btnx
               Btnx.Location = New System.Drawing.Point(5, 85)
               Btnx.Text = "Send"
               Btnx.Name = "Btnx" & (i + 1).ToString
               Btnx.BackColor = System.Drawing.Color.White
               Btnx.Size = New System.Drawing.Size(100, 25)
           End With
           Dim Panx As Panel = New Panel
           With Panx
               Panx.Location = pt
               Panx.BackColor = System.Drawing.Color.Silver
               Panx.Size = New System.Drawing.Size(111, 111)
           End With
           Dim Picx As PictureBox = New PictureBox
           With Picx
               Picx.Location = New System.Drawing.Point(30, 5)
               Picx.Size = New System.Drawing.Size(50, 50)
               Picx.BackColor = System.Drawing.Color.White
           End With
           Dim Labx As Label = New Label
           With Picx
               Labx.Location = New System.Drawing.Point(0, 63)
               Labx.Size = New System.Drawing.Size(111, 15)
               Labx.Text = "{NAME}"
               Labx.TextAlign = System.Drawing.ContentAlignment.TopCenter
           End With

           ' هنا يتم ضبط مكان كل باتون
           pt.X += Panx.Height + 95
           Panx.Controls.Add(Btnx)
           Panx.Controls.Add(Picx)
           Panx.Controls.Add(Labx)
           FlowLayoutPanel1.Controls.Add(Panx)
       Next
       ' هنا نضيف الحدث لكل باتون

       For Each b As Button In Me.Controls.OfType(Of Button)()
           AddHandler b.Click, AddressOf Btnx_Click
       Next
   End Sub
   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Name
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"


           Case "Btnx3"


           Case "Btnx4"
               Close()




       End Select

   End Sub
End Class
الرد }}}
تم الشكر بواسطة: asemshahen5 , bidaya
#4
(05-02-20, 03:40 PM)Sorax كتب : شكرا بس بعد التعديل بعد ميشتغل الهاندلس

كود :
Public Class Form2


   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Dim pt As Point = New Point(10, 10)
       For i As Integer = 0 To 3
           Dim Btnx As Button = New Button
           With Btnx
               Btnx.Location = New System.Drawing.Point(5, 85)
               Btnx.Text = "Send"
               Btnx.Name = "Btnx" & (i + 1).ToString
               Btnx.BackColor = System.Drawing.Color.White
               Btnx.Size = New System.Drawing.Size(100, 25)
           End With
           Dim Panx As Panel = New Panel
           With Panx
               Panx.Location = pt
               Panx.BackColor = System.Drawing.Color.Silver
               Panx.Size = New System.Drawing.Size(111, 111)
           End With
           Dim Picx As PictureBox = New PictureBox
           With Picx
               Picx.Location = New System.Drawing.Point(30, 5)
               Picx.Size = New System.Drawing.Size(50, 50)
               Picx.BackColor = System.Drawing.Color.White
           End With
           Dim Labx As Label = New Label
           With Picx
               Labx.Location = New System.Drawing.Point(0, 63)
               Labx.Size = New System.Drawing.Size(111, 15)
               Labx.Text = "{NAME}"
               Labx.TextAlign = System.Drawing.ContentAlignment.TopCenter
           End With

           ' هنا يتم ضبط مكان كل باتون
           pt.X += Panx.Height + 95
           Panx.Controls.Add(Btnx)
           Panx.Controls.Add(Picx)
           Panx.Controls.Add(Labx)
           FlowLayoutPanel1.Controls.Add(Panx)
       Next
       ' هنا نضيف الحدث لكل باتون

       For Each b As Button In Me.Controls.OfType(Of Button)()
           AddHandler b.Click, AddressOf Btnx_Click
       Next
   End Sub
   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Name
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"


           Case "Btnx3"


           Case "Btnx4"
               Close()




       End Select

   End Sub
End Class



لا تحتاج لتحديد Location لاداة Panel لان الاداة FlowLayoutPanel هي من تحدد مكانها بشكل تلقائي

كود :
   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

       For i = 0 To 3

           Dim Panx As New Panel
           Panx.Size = New Size(111, 111)
           Panx.BackColor = Color.Silver
           FlowLayoutPanel1.Controls.Add(Panx)

           Dim Picx As New PictureBox
           Picx.Size = New Size(50, 50)
           Picx.Location = New Point(30, 5)
           Picx.BackColor = Color.White
           Panx.Controls.Add(Picx)

           Dim Labx As New Label
           Labx.Size = New Size(111, 15)
           Labx.Location = New Point(0, 63)
           Labx.Text = "{NAME}"
           Labx.TextAlign = ContentAlignment.TopCenter
           Panx.Controls.Add(Labx)

           Dim Btnx As New Button
           Btnx.Size = New Size(100, 25)
           Btnx.Location = New Point(5, 85)
           Btnx.Name = "Btnx" & (i + 1).ToString
           Btnx.BackColor = Color.White
           Btnx.Text = "Send"
           AddHandler Btnx.Click, AddressOf Btnx_Click
           Panx.Controls.Add(Btnx)

       Next

    End Sub
الرد }}}
تم الشكر بواسطة: asemshahen5 , Sorax
#5
اعتذر بس اريد الكود نفس هذا وتكون الهاندلس شغاله
لان كودك الاخير بيه خطا
كود :
  Private Sub Formx_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       For i As Integer = 0 To 3
           Dim Btnx As Button = New Button
           With Btnx
               Btnx.Location = New System.Drawing.Point(5, 85)
               Btnx.Text = "Send"
               Btnx.Name = "Btnx" & (i + 1).ToString
               Btnx.BackColor = System.Drawing.Color.White
               Btnx.Size = New System.Drawing.Size(100, 25)
           End With
           Dim Panx As Panel = New Panel
           With Panx
               Panx.BackColor = System.Drawing.Color.Silver
               Panx.Size = New System.Drawing.Size(111, 111)
           End With
           Dim Picx As PictureBox = New PictureBox
           With Picx
               Picx.Location = New System.Drawing.Point(30, 5)
               Picx.Size = New System.Drawing.Size(50, 50)
               Picx.BackColor = System.Drawing.Color.White
           End With
           Dim Labx As Label = New Label
           With Picx
               Labx.Location = New System.Drawing.Point(0, 63)
               Labx.Size = New System.Drawing.Size(111, 15)
               Labx.Text = "{NAME}"
               Labx.TextAlign = System.Drawing.ContentAlignment.TopCenter
           End With
           Panx.Controls.Add(Btnx)
           Panx.Controls.Add(Picx)
           Panx.Controls.Add(Labx)
           FlowLayoutPanel1.Controls.Add(Panx)
       Next
       ' هنا نضيف الحدث لكل باتون

       For Each b As Button In Me.Controls.OfType(Of Button)()
           AddHandler b.Click, AddressOf Btnx_Click
       Next
   End Sub
   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Name
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"


           Case "Btnx3"


           Case "Btnx4"
               Close()




       End Select

   End Sub
الرد }}}
تم الشكر بواسطة: asemshahen5 , bidaya
#6
(05-02-20, 09:08 PM)Sorax كتب : اعتذر بس اريد الكود نفس هذا وتكون الهاندلس شغاله
لان كودك الاخير بيه خطا
كود :
  Private Sub Formx_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       For i As Integer = 0 To 3
           Dim Btnx As Button = New Button
           With Btnx
               Btnx.Location = New System.Drawing.Point(5, 85)
               Btnx.Text = "Send"
               Btnx.Name = "Btnx" & (i + 1).ToString
               Btnx.BackColor = System.Drawing.Color.White
               Btnx.Size = New System.Drawing.Size(100, 25)
           End With
           Dim Panx As Panel = New Panel
           With Panx
               Panx.BackColor = System.Drawing.Color.Silver
               Panx.Size = New System.Drawing.Size(111, 111)
           End With
           Dim Picx As PictureBox = New PictureBox
           With Picx
               Picx.Location = New System.Drawing.Point(30, 5)
               Picx.Size = New System.Drawing.Size(50, 50)
               Picx.BackColor = System.Drawing.Color.White
           End With
           Dim Labx As Label = New Label
           With Picx
               Labx.Location = New System.Drawing.Point(0, 63)
               Labx.Size = New System.Drawing.Size(111, 15)
               Labx.Text = "{NAME}"
               Labx.TextAlign = System.Drawing.ContentAlignment.TopCenter
           End With
           Panx.Controls.Add(Btnx)
           Panx.Controls.Add(Picx)
           Panx.Controls.Add(Labx)
           FlowLayoutPanel1.Controls.Add(Panx)
       Next
       ' هنا نضيف الحدث لكل باتون

       For Each b As Button In Me.Controls.OfType(Of Button)()
           AddHandler b.Click, AddressOf Btnx_Click
       Next
   End Sub
   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Name
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"


           Case "Btnx3"


           Case "Btnx4"
               Close()




       End Select

   End Sub

لم تحدد الاخطاء

اخي هو الان مجرب امامي ويعمل بدون اخطاء تفضل نسخ كالم الكود من المشروع الذي امامي الان
ولصق هنا ولا تنس ان تضيف اداة FlowLayoutPanel1
كود :
Public Class Form2


   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Me.DataGridView1.Columns(1).Visible = False
       For i = 0 To 3

           Dim Panx As New Panel
           Panx.Size = New Size(111, 111)
           Panx.BackColor = Color.Silver
           FlowLayoutPanel1.Controls.Add(Panx)

           Dim Picx As New PictureBox
           Picx.Size = New Size(50, 50)
           Picx.Location = New Point(30, 5)
           Picx.BackColor = Color.White
           Panx.Controls.Add(Picx)

           Dim Labx As New Label
           Labx.Size = New Size(111, 15)
           Labx.Location = New Point(0, 63)
           Labx.Text = "{NAME}"
           Labx.TextAlign = ContentAlignment.TopCenter
           Panx.Controls.Add(Labx)

           Dim Btnx As New Button
           Btnx.Size = New Size(100, 25)
           Btnx.Location = New Point(5, 85)
           Btnx.Name = "Btnx" & (i + 1).ToString
           Btnx.BackColor = Color.White
           Btnx.Text = "Send"
           AddHandler Btnx.Click, AddressOf Btnx_Click
           Panx.Controls.Add(Btnx)

       Next

    End Sub


   Private Sub Btnx_Click(sender As Object, e As EventArgs)
       ' اكتب ما تريده في الحدث
       ' هنا نختار الباتون بناء علي التكست الخاص به
       ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
       Dim Btnx As Button = CType(sender, Button)
       Select Case Btnx.Name
           Case "Btnx1"
               Text = "Sorax"

           Case "Btnx2"

           Case "Btnx3"

           Case "Btnx4"
               Close()

       End Select

   End Sub

End Class
الرد }}}
تم الشكر بواسطة: asemshahen5 , asemshahen5 , Sorax , bidaya
#7
كود :
 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        Dim panel As Panel = New Panel
        With panel
            panel.Location = New System.Drawing.Point(262, 92)
            panel.Size = New System.Drawing.Size(492, 155)
            panel.BackColor = Color.Bisque
            Me.Controls.Add(panel)
        End With

        ''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''

        Dim pt As Point = New Point(50, 10)
        For i As Integer = 0 To 3
            Dim Btnx As Button = New Button
            With Btnx
                Btnx.Location = pt
                Btnx.Text = "Btnx" & (i + 1).ToString
                Btnx.Cursor = Cursors.Hand
                Btnx.Size = New System.Drawing.Size(52, 22)
                ' إضبط خصائص الباتون كيفما شئت
            End With
            ' هنا يتم ضبط مكان كل باتون
            pt.X += Btnx.Height + 55

            'هنا اضافة الادات الى البنل
            panel.Controls.Add(Btnx)

        Next







        '    هنا نضيف الحدث  لكل بوتن داخل البانل

        For Each b As Button In panel.Controls.OfType(Of Button)()
            AddHandler b.Click, AddressOf Btnx_Click
        Next
    End Sub
    Private Sub Btnx_Click(sender As Object, e As EventArgs)
        ' اكتب ما تريده في الحدث
        ' هنا نختار الباتون بناء علي التكست الخاص به
        ' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
        Dim Btnx As Button = CType(sender, Button)
        Select Case Btnx.Text
            Case "Btnx1"
                Text = "Sorax"

            Case "Btnx2"


            Case "Btnx3"


            Case "Btnx4"
                Close()




        End Select

    End Sub
End Class
الرد }}}
تم الشكر بواسطة: asemshahen5 , Sorax
#8
شكرا ي شباب مقصرتو ورب
والحل هو بنفس الكود المعدل مالتي وبس تخلي هذا لكود بداخل اول for

AddHandler Btnx.Click, AddressOf Btnx_Click

واحب اشكركم مرة ثانيه وبالتوفيق للكل
الرد }}}
تم الشكر بواسطة: bidaya , asemshahen5



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


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