Click here to Skip to main content
15,667,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning everyone

i call 2 method from a class i assume it as "hiddenButton" class
one is to set the visibility of button
another method is the hide the button

i already initialize the button and hide it when the program has run

to show the button from hiddenButton
i have to click on the button from the main form and i assume it as "show button"
if i click on the "show button", it will actually hide away the button

without removing the eventhandler, when i click on the "show button" it should be show and hide my button

but my button from "hiddenButton" class only show and hide once, then it doesn't work anymore.

I already try my eventhandler by using messagebox, when i click on the "show button", it actually pop up the messagebox without any problem

so i wonder why the button of "hidden button" only show and hide once then it doesn't work

is that because my button was actually set on the same location with other object on the form?

What I have tried:

from main code
<br />
dim _hiddenButton as new hiddenButton<br />
_hiddenButton.initButton(form1) 'add button to form 1<br />
dim _otherElement as new otherElement<br />
_otherElement.initElement(from1) 'add other element to form1<br />
dim _button as button = new button<br />
with _button<br />
.text = "show button"<br />
addhandler .mouseclick, addressof bmClicked<br />
end with<br />
form1.controls.add(_button)<br />
<br />
private sub bmClicked(byval sender as object, byval e as eventargs)<br />
dim _button as button = sender<br />
<br />
with _button<br />
if .text = "Show Me" then<br />
.text = "Hide me"<br />
hiddenButton.buttonShow()<br />
else if .text = "Hide Me" then<br />
.text = "Sow Me" then<br />
hiddenButton.hideButton()<br />
end with<br />
end sub<br />

code from hiddenButton Class
<pre lang="vb">
private shared _button as button
public sub initButton(byval formName as form)
_button = new button
with _button
.text = "hello code project"
.size = new size(100, 100)
.location = new point(30,30)
.visible = false
end with
end sub

public shared sub buttonShow()
_button.visible = true
end sub

public shared sub buttonHide()
_button.visible = false
end sub

class from otherElement
private _backgroundPanel as panel

public sub initElement(byval fromName as form)
_backgroundPanel = new panel

with _backgroundpanel
.backgroundcolor =
.size = new size (screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height)
.location = new point(0,0)
end with
end sub
Updated 22-Feb-17 16:31pm

1 solution

You should learn to use the debugger built into Visual Studio. Here is a Basic Debugging with Visual Studio 2010[^] video that will get you started.

What do you see is wrong with this line?
.text = "Sow Me" then
Share this answer
Ralf Meier 23-Feb-17 1:44am    
I think with this codeline the Debugger doesn't help because this line would not compiled ...
But I had to look 2 times to see this code-error - very good ... +5
Graeme_Grant 23-Feb-17 2:08am    
VB has a With statement for the object, so this line is legal. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900