vb.net - how to programmatically hide toolstrip buttons

Hi Experts,

I want to be able to programmatically hide some toolstrip buttons.

I've tried code like:

ToolStripButtonTLD.Visible = False

Open in new window


But that doesn't work.

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
You need to use the Available property.

ToolStripButtonTLD.Available= False

Open in new window


https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.toolstripbutton
0
LeighWardleAuthor Commented:
Hi Paul,

Thanks, but the .Available property is not working for me.

Do I need to combine it with the .Visible property? or something else?

Regards,
Leigh
0
Paul JacksonSoftware EngineerCommented:
Can you post some code, in what scenario are you setting the .Visible/.Available properties ?
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

LeighWardleAuthor Commented:
Hi Paul,

I created a simple test code - and .Available worked fine.

My production code is many thousands of lines, but here is the excerpt that attempts to toggle the visibility of the toolbarstrip buttons:

            ' Configure toolbar icons
            Select Case g_enumDesignMethodCurrent
                Case enumDesignMethod.enumDesignMethod_AustroadsDesign '"Austroads Pavement Design (2017)"

                    'deactivate/activate various features
                    ToolStripButtonTLD.Available = True
                    ToolStripButtonHaulTrucks.Available = False
                    ToolStripButtonLoads.Available = False
                    ToolStripButtonTraffic.Available = False
                    ToolStripButtonCoordinates.Available = False
                    ToolStripButtonGraph.Available = gboolParametricAnalysis '20180319
                    ToolStripButtonMax.Available = False
                    PlotResultsToolStripMenuItem.Available = False

                Case enumDesignMethod.enumDesignMethod_GeneralDesign, enumDesignMethod.enumDesignMethod_GeneralAnalysis '"General Design", "General Analysis"

                    ToolStripButtonTLD.Available = False
                    ToolStripButtonHaulTrucks.Available = False
                    ToolStripButtonLoads.Available = True
                    ToolStripButtonTraffic.Available = True
                    ToolStripButtonCoordinates.Available = True
                    ToolStripButtonGraph.Available = True '20180319
                    'If g_enumDesignMethodCurrent <> enumDesignMethod.enumDesignMethod_HaulRoadDesign Then
                    '    ToolStripButtonGraph.Available = True
                    'Else
                    '    ToolStripButtonGraph.Available = False
                    'End If
                    PlotResultsToolStripMenuItem.Available = True

                Case enumDesignMethod.enumDesignMethod_HaulRoadDesign '"Haul Road Design"

                    ToolStripButtonTLD.Available = False
                    ToolStripButtonLoads.Available = False
                    ToolStripButtonTraffic.Available = False
                    ToolStripButtonCoordinates.Available = False
                    ToolStripButtonGraph.Available = True '20180319
                    ToolStripButtonHaulTrucks.Available = True
                    PlotResultsToolStripMenuItem.Available = True
            End Select

Open in new window


When I step through the code one statement at a time, after executing this statement:
ToolStripButtonTLD.Available = False

Open in new window


The button, ToolStripButtonTLD, is still visible.

A watch on ToolStripButtonTLD.visible shows that it is False.

Regards,
Leigh
0
Paul JacksonSoftware EngineerCommented:
Yes but in what method/function is this code called ? InitializeComponent(), Load_Form() or somewhere else?
The Visible property will often seem to have the wrong value because it only gets updated once the control is rendered, hence the question where and when is the code called.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Hi Paul,

Yes, the problematic code was being called by Load_Form().
I've refactored my code and it's working now.

Thanks for you help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.