事件处理程序正在运行但方法不起作用

事件处理程序正在运行但方法不起作用

本文介绍了事件处理程序正在运行但方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好大家



i来自一个类的2方法我认为它是hiddenButton类

一个是设置可见性按钮

另一种方法是隐藏按钮



i已经初始化按钮并在程序运行时隐藏它



显示来自hiddenButton的按钮

i必须点击主窗体上的按钮,我认为它是显示按钮

如果我点击显示按钮,它实际上会隐藏按钮



而不删除事件处理程序,当我点击显示按钮时应该显示并隐藏我的按钮



但是我的hiddenButton类的按钮只显示和隐藏一次,然后它不再起作用了。



我已经通过使用messagebox尝试我的事件处理程序,当我点击显示按钮时,它实际上弹出了消息框没有任何问题



所以我想知道为什么按钮隐藏按钮只显示和隐藏一次然后它不起作用



是因为我的按钮实际上与表格上的其他对象设置在同一位置?



我尝试过:



来自主码

< br /> 
dim _hiddenButton as new hiddenButton< br />
_hiddenButton.initButton(form1)'添加按钮以形成1< br />
dim _otherElement as new otherElement< br />
_otherElement.initElement(from1)'将其他元素添加到form1< br />
dim _button as button = new button< br />
with _button< br />
.text =show button< br />
addhandler .mouseclick,address of bmClicked< br />
以< br /> $ b结束$ b form1.controls.add(_button)< br />
< br />
private sub bmClicked(byval sender as object,byval e as eventargs)< br />
使用_button< br />
如果.text = lt; br />
.text =隐藏我< br />
hiddenButton.buttonShow()< br />
else if .text =Hide Methen< br />
.text =Sow Me然后< br />
hiddenButton.hideButton()< br />
以< br />
end sub<结尾br />





来自hiddenButton类的代码

< 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 =新尺寸(100,100)
.location =新点(30,30)
.visible = false

结尾formName.controls.add( _button)
end sub

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

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





来自otherElement的课程

 private _backgroundPanel as panel 

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

with _backgroundpanel
。 backgroundcolor = color.black
.size =新尺寸(screen.primaryscreen.bounds.width,screen.primaryscreen.bounds.height)
.location = new point(0,0)
end with
formName.controls.add(_background)
end sub
解决方案

您应该学习使用Visual Studio内置的调试器。这是 []视频将帮助您入门。



您认为这条线路有什么问题?

。 =   Sow Me 然后 


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
formName.controls.add(_button)
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 = color.black
.size = new size (screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height)
.location = new point(0,0)
end with
formName.controls.add(_background)
end sub
解决方案
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


这篇关于事件处理程序正在运行但方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:42