منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : كيفي عمل التفعيل و التعطيل للقوائم في ToolStrip
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
[COLOR="#0000CD"]السلام عليكم و رحمة الله

أخواني و أخواتي الكرام في المنتدى، لدي مشكلة في كيفية تفعيل و تعطيل (Enable = True/False) القوائم في أداة ToolStrip مرة واحد، حيث أنني لا أريد أن أكتبها قائمة تلو الأخرى للتفعيل و التعطيل.
و من محاولاتي كان هذا الكود التالي و لكنه لم ينجح
PHP كود :
Private Sub SetToolStrip(ByRef toolstrip As ToolStripByVal enable As Boolean)
        
Dim c As ToolStripItem
        Dim t 
As ToolStripSplitButton

        
For Each c In toolstrip.Items
            c
.Enabled enable
            
If c.GetType Is GetType(ToolStripSplitButtonThen
                t 
c
                SetToolStrip
(t.DropDownItemsenable)
            
End If
        
Next
    End Sub

    
Private Sub SetToolStrip(ByRef stripitem As ToolStripItemCollectionByVal enable As Boolean)
        
Dim c As ToolStripItem
        Dim t 
As ToolStripSplitButton

        
For Each c In stripitem
            c
.Enabled enable
            
If c.GetType Is GetType(ToolStripSplitButtonThen
                t 
c
                SetToolStrip
(t.DropDownItemsenable)
            
End If
        
Next
    End Sub

Private Sub Main_Form_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load
SetToolStrip
(ToolStrip1True)
End Sub 

أتمنى أن ألقى الإجابة منكم و أنا ممنون لكم في الإجابة أو عدم الإجابة.
[/COLOR]
السلام عليكم ورحمة الله وبركاته

عملت لك كود علي السريع :
كود :
Private Sub EnabeldToolStripControls(ByVal b As Boolean)


        For Each button In ToolStrip1.Items.OfType(Of ToolStripButton)()
            button.Enabled = b
        Next


        For Each DropDown In ToolStrip1.Items.OfType(Of ToolStripDropDownButton)()
            ' DropDown.Enabled = b
            If DropDown.HasDropDownItems Then
                For Each btn In DropDown.DropDown.Items.OfType(Of ToolStripDropDownItem)()
                    btn.Enabled = b
                Next
            End If
        Next


    End Sub


إذا كان الزر من نوع DropDown وأردت تفعيل وتعطيل أزراره الداخلية فقط يمكن استخدام الكود السابق . أما إذا أردت تفعيله وتعطيله هو نفسه فاستخدم الكود أدناه :
كود :
Private Sub EnabeldToolStripControls(ByVal b As Boolean)


        For Each button In ToolStrip1.Items.OfType(Of ToolStripButton)()
            button.Enabled = b
        Next


        For Each DropDown In ToolStrip1.Items.OfType(Of ToolStripDropDownButton)()
            DropDown.Enabled = b
            'If DropDown.HasDropDownItems Then
            '    For Each btn In DropDown.DropDown.Items.OfType(Of ToolStripDropDownItem)()
            '        btn.Enabled = b
            '    Next
            'End If
        Next


    End Sub
جاري التجربة و ما قصرت يا كبير

تسلم يا رب و كل عام و إنت بخير يا صديقي و ينعاد عليكم بكل خير
كل عام و إنت بخير
للأسف أخ كسلاوي لم ينجح الأمر و مازلت أحاول فيها و في نفس الوقت هذا مثال للموضوع نفسه في المرفقات
كود :
If CheckBox1.Checked = True Then
            ToolStrip1.Enabled = False
        Else
            ToolStrip1.Enabled = True
        End If
أخ سعود الموضوع هنا مختلف ممكن تشوف المثال و تعطيني رأيك
اطلعت على المثال ولم افهم شي معلش Smile
ان كان القصد تعطيل الاداة بالكامل فلا اريح من الكود اللي انا كتبته اما لو المقصود تعطيل عمود معين وكافة ابناءه فلم اتطرق لهذا من قبل وان شاء الله تجد الحل
مشكور على مجهودك أخ سعود و ما قصرت والله، المقصود في التعطيل هو تعطيل أو تفعيل جميع القوائم من أبناء و أحفاد لأي زر من الأداة
السلام عليكم ورحمة الله وبركاته

كود :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        DisableAllButtons(ToolStrip1, True)


    End Sub


    Public Sub DisableAllButtons(ByVal ts As ToolStrip, ByVal b As Boolean)
        Dim i As Integer = 0
        For i = 0 To ts.Items.Count - 1
            Child(ts.Items(i), b)
        Next
    End Sub


    Private Sub Child(ByVal DDI As ToolStripDropDownItem, ByVal b As Boolean)
        For Each itm As ToolStripDropDownItem In DDI.DropDownItems
            itm.Enabled = b
            If itm.HasDropDownItems Then
                For Each it As ToolStripDropDownItem In itm.DropDownItems
                    Child(it, b)
                Next
                For Each it As ToolStripMenuItem In itm.DropDownItems
                    it.Enabled = b
                Next
            End If
        Next
    End Sub


****
***
**
*