|
-
Nov 9th, 2006, 09:49 AM
#1
Thread Starter
Member
MenuStrip [This should be easy]
Being stuck in this for 1 day... in VB6, when we cant to invoke an object method, having the name of it in a string, we could do something like:
VB Code:
Dim Description as Sring
Description = "Menu1"
FrmStart(Description).Eabled = False
Now, on Vb.net, we cant simply do the same, as it throws an error, because the menu is inside an other object. But, if i call the Menu1.enabled, on the code, it allows me with no problem. The problem is the "Menu1" is inside a string. I think this must have an easy solution, but i've been strugling all day and no clue
-
Nov 9th, 2006, 12:46 PM
#2
Re: MenuStrip [This should be easy]
Here is one way to do it... Just loop thru all controls on the form to find the right control using control name, then disable it when found
VB Code:
'This is for a Form
Dim controlName As String = "Button1"
For Each ctrl As Control In Me.Controls
If ctrl.Name = controlName Then
ctrl.Enabled = False
End If
Next
'And this is for a MenuStrip
Dim controlName As String = "FileToolStripMenuItem"
For Each ctrl As ToolStripItem In Me.MenuStrip1.Items
If ctrl.Name = controlName Then
ctrl.Enabled = False
End If
Next
Last edited by stanav; Nov 9th, 2006 at 01:01 PM.
-
Nov 9th, 2006, 01:03 PM
#3
Thread Starter
Member
Re: MenuStrip [This should be easy]
The problem of that code, code i have, is the slowness of it. I must cicle all the menus, or part of them, for each menu item i've. The program is working that way atm, just wanted do make ir quicker, but it seems not easy.
-
Nov 9th, 2006, 01:15 PM
#4
Re: MenuStrip [This should be easy]
Instead of looping through the controls you can go directly at it using:
VB Code:
Dim c As Control = Me.Controls.Item(controlName)
c.Enabled = False
and for the menu:
VB Code:
Try
Dim c As ToolStripItem = MenuStrip1.Items.Item(controlName)
c.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Last edited by Atheist; Nov 9th, 2006 at 01:21 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|