منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
ما هو اختصار هذه الاكواد - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : ما هو اختصار هذه الاكواد (/showthread.php?tid=47467)



ما هو اختصار هذه الاكواد - justforit - 10-11-23


السلام عليكم
مساء الخير
PHP كود :
 Private Sub clearAllTextBoxes(ctl As Control)
 
     If TypeOf ctl Is TextBox Then
          CType
(ctlTextBox).Clear()
 
     ElseIf ctl.HasChildren Then
          For Each c 
As Control In ctl.Controls
              If TypeOf c Is TextBox Then
                  CType
(cTextBox).Clear()
 
             ElseIf c.HasChildren Then
                  For Each h 
As Control In c.Controls
                      If TypeOf h Is TextBox Then
                          CType
(hTextBox).Clear()
 
                     End If
 
                 Next
              End 
If
 
         Next
      End 
If
 
 End Sub
  Private Sub fillAlltextBoxes
(ctl As Control)
 
     If TypeOf ctl Is TextBox Then
          CType
(ctlTextBox).Text ctl.Name
      ElseIf ctl
.HasChildren Then
          For Each c 
As Control In ctl.Controls
              If TypeOf c Is TextBox Then
                  CType
(cTextBox).Text c.Name
              ElseIf c
.HasChildren Then
                  For Each h 
As Control In c.Controls
                      If TypeOf h Is TextBox Then
                          CType
(hTextBox).Text h.Name
                      End 
If
 
                 Next
              End 
If
 
         Next
      End 
If
 
 End Sub 

كما ترون بالكود حلقات متداخلة فهل توجد طريقة تختصر هذه الاكواد؟

PHP كود :
 Private Sub ClearTextBoxes(ByVal root As Control)
 
     For Each ctrl As Control In root.Controls
          ClearTextBoxes
(ctrl)
 
         If TypeOf ctrl Is TextBox Then
              CType
(ctrlTextBox).Text String.Empty
 
         End If
 
     Next ctrl
  End Sub
  Private Sub fill
(ByVal root As Control)
 
     For Each ctrl As Control In root.Controls
          fill
(ctrl)
 
         If TypeOf ctrl Is TextBox Then
              CType
(ctrlTextBox).Text ctrl.Name
          End 
If
 
     Next ctrl
  End Sub 
وجدت الكود ووضعته للفائدة.


RE: ما هو اختصار هذه الاكواد - Ashraf10 - 10-11-23

مشاركة لكم :
PHP كود :
Private Sub ClearTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text "" Else ClearTextBoxes(c))
End Sub 

PHP كود :
Private Sub FillTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text c.Name Else FillTextBoxes(c))
End Sub 
ايه الفايده من FillTextBoxes


RE: ما هو اختصار هذه الاكواد - justforit - 11-11-23

(10-11-23, 11:48 PM)Ashraf10 كتب : مشاركة لكم :
PHP كود :
Private Sub ClearTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text "" Else ClearTextBoxes(c))
End Sub 

PHP كود :
Private Sub FillTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text c.Name Else FillTextBoxes(c))
End Sub 
ايه الفايده من FillTextBoxes
ههههههههههههه
هذا فقط للسرعة عشان اجرب


RE: ما هو اختصار هذه الاكواد - kebboud - 19-11-23

(11-11-23, 12:10 AM)justforit كتب :
(10-11-23, 11:48 PM)Ashraf10 كتب : مشاركة لكم :
PHP كود :
Private Sub ClearTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text "" Else ClearTextBoxes(c))
End Sub 

PHP كود :
Private Sub FillTextBoxes(ByVal ctrl As Control)
 
   Array.ForEach(ctrl.Controls.OfType(Of Control).ToArraySub(c) If TypeOf c Is TextBox Then c.Text c.Name Else FillTextBoxes(c))
End Sub 
ايه الفايده من FillTextBoxes
ههههههههههههه
هذا فقط للسرعة عشان اجرب
بسم الله الرحمن الرحيم
كيف يمكن استدعاء هذه الدالة (ClearTextBoxes)


RE: ما هو اختصار هذه الاكواد - salamandal - 22-01-24

[/quote]
بسم الله الرحمن الرحيم
كيف يمكن استدعاء هذه الدالة (ClearTextBoxes)
[/quote]

           ClearTextBoxes(Me)

         FillTextBoxes(Form1)