Hidden buttons in toolbar can still be clicked, how come ?

D

/dev/null

Hello,
i am using visual studio 2003 enterprise architect version. I am making
apps for the .Net framework 1.1. While testing an interface, i discovered
something strange.

In this application we have a standard toolbar that is at the top of the
form window. It contains about 8 buttons that use images from an imagelist.
Sometimes we hide buttons thru the code.

When a button is hidden, i assumed that it wasn't clickable. It appears
that horizontally across the toolbar, the top 2 pixels become some sort of
button. When i click at the top of the toolbar where normally there
shouldn't be anything, it activates one of the hidden buttons. To the eye,
everything seems fine but when i click in this area it generates a
ToolBar.ButtonClick event and e.button contains the properties of the hidden
button.

How come ? I've tried to search the web but couldn't find anything.
 
Z

zacks

Hello,
i am using visual studio 2003 enterprise architect version. I am making
apps for the .Net framework 1.1. While testing an interface, i discovered
something strange.

In this application we have a standard toolbar that is at the top of the
form window. It contains about 8 buttons that use images from an imagelist.
Sometimes we hide buttons thru the code.

When a button is hidden, i assumed that it wasn't clickable. It appears
that horizontally across the toolbar, the top 2 pixels become some sort of
button. When i click at the top of the toolbar where normally there
shouldn't be anything, it activates one of the hidden buttons. To the eye,
everything seems fine but when i click in this area it generates a
ToolBar.ButtonClick event and e.button contains the properties of the hidden
button.

How come ? I've tried to search the web but couldn't find anything.

Just hiding a button (setting the Visible property to False) does not
disable it. You need to also set the Enabled property to False.
 
J

Jerry Spence1

** Just hiding a button (setting the Visible property to False) does not
disable it. You need to also set the Enabled property to False.**

Uh? I'm with zacks on this one. If you hide it, there is nothing to click
on. I've just tried it. However, I get a Toolbar Click event, not a
ButtonClick Event.

-Jerry
 
Z

zacks

** Just hiding a button (setting the Visible property to False) does not
disable it. You need to also set the Enabled property to False.**

Uh? I'm with zacks on this one. If you hide it, there is nothing to click
on. I've just tried it. However, I get a Toolbar Click event, not a
ButtonClick Event.

-Jerry

Well, I spoke too soon on this. Turns out the click event for the
toolstrip button does not fire if the control is merely set to not
visible. BUT, if you have and Click event handler for the Toolstrip
itself, then, yes, if you click on the toolstrip where the invisible
button is, the toolstrip's Click event WILL fire.
 
D

/dev/null

Seems i didn't explain it properly.

Here is some code :
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
If e.Button Is Me.NewButton Then
MsgBox("New")
ElseIf e.Button Is Me.CopyButton Then
MsgBox("Copy")
ElseIf e.Button Is Me.CutButton Then
MsgBox("Cut")
ElseIf e.Button Is Me.HelpButton Then
MsgBox("Help")
End If
End Sub

I am talking about the buttonclick event of a toolbar.

When i hide one button and leave the 3 others, strange things will happen.

I tried it in a new project and the problem duplicates.

If i click on the toolbar where no button is, this event is generally not
fired and nothing happens, which is what i want.

However, and here is the catch, if i click at the top of the toolbar, in a
zone of about 2 pixels high and that covers the whole width of my form, the
event is fired and the content of e.Button is the hidden button. You can't
see a delimitation for this zone but it catches clicks.

I've shown it to other devs here and no one seems to know what is causing
this.

This is really strange, the original button is just 16x16 or 32x32 pixels.

Thanks a lot for taking the time to help me out.
 
Z

zacks

Seems i didn't explain it properly.

Here is some code :
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
If e.Button Is Me.NewButton Then
MsgBox("New")
ElseIf e.Button Is Me.CopyButton Then
MsgBox("Copy")
ElseIf e.Button Is Me.CutButton Then
MsgBox("Cut")
ElseIf e.Button Is Me.HelpButton Then
MsgBox("Help")
End If
End Sub

I am talking about the buttonclick event of a toolbar.

When i hide one button and leave the 3 others, strange things will happen.

I tried it in a new project and the problem duplicates.

If i click on the toolbar where no button is, this event is generally not
fired and nothing happens, which is what i want.

However, and here is the catch, if i click at the top of the toolbar, in a
zone of about 2 pixels high and that covers the whole width of my form, the
event is fired and the content of e.Button is the hidden button. You can't
see a delimitation for this zone but it catches clicks.

I've shown it to other devs here and no one seems to know what is causing
this.

This is really strange, the original button is just 16x16 or 32x32 pixels.

Thanks a lot for taking the time to help me out.

Is there some reason why you are using the Toolbar ButtonClick event
to handle all toolbar button's being clicked instead of each button's
own Click event?
 
D

/dev/null

Seems i just can't proceed this way. I tried to define the event handler in
vb.net and the dropdown list in the vb.net interface lets me handle the
disposed event and that's it. I tried to define the event handler manually
and i get Event 'Click' cannot be found.

From what i understand, i have to use the ToolBar.ButtonClick event.

I can fix the problem by removing the unwanted buttons from the toolbar in
the form.load event but the whole behavior with hidden buttons seemed so
strange.

Your suggestion was brilliant though as i really didn't think of that.

I'm still seeking explanations on why this behavior occurs with my toolbars
(it occurs in the app i'm developing and in the test form i made too).

Thanks a lot for taking all this time to answer my question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top