|
|
 |
BOOK: Visual Basic 2005 Programmer's Reference  | This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

March 14th, 2008, 01:40 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to fire an Event
Hi Rod,
I created one control (mylistbox) and use that in my program (which has one textbox and mylistbox). When the user click on my control (mylistbox) i want to fire the textbox_click event. how can i?
Regards
ackid32
|

March 14th, 2008, 11:07 AM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Location: , , .
Posts: 125
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If you just want the event handler to run, you can invoke it directly as in:
TextBox1_TextChanged(Nothing, Nothing)
This assumes the event handler doesn't use its parameters for anything. If it does, pass the TextBox in as the Sender and build a System.EventArgs to pass for the second argument.
If you truly want to raise the event, for example if you don't know what event handlers are attached to it, you have a couple of choices.
Easiest is to change the text. Unfortunately that changes the text (duh!) so if you want the text to remain unchanged you need to change it back, which raises another event. Not a great solution.
A more "correct" solution is to subclass TextBox to make a new control, say MyTextBox. Give it a method that calls the OnTextChanged subroutine. This routine raises the event. (Controls have other OnXxx methods that raise other events but all of them are hidden inside the class so you have to subclass to find them.
Public Class MyTextBox
Inherits TextBox
Public Sub RaiseChangedEvent()
Me.OnTextChanged(Nothing)
End Sub
End Class
Now the main program can call this control's RaiseChangedEvent method. Again you'll need to build a System.EventArgs object if the event handler(s) needs one.
You could probably also send the TextBox some sort of message but I don't know exactly how you would manage that approach.
I hope that helps,
Rod
Rod Stephens, Visual Basic MVP
RodStephens@vb-helper.com
*** New Book ***
"Visual Basic 2008 Programmer's Reference"
Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
|

March 15th, 2008, 12:50 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi, i don't want to raise any events, i already have the textbox_click event in my main program, all i want is that When the user click on my control (mylistbox) i want to call the textbox_click event. how can i?
|

March 15th, 2008, 12:53 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
remember that mylistbox is in a dll (which was created by myself)
|

March 15th, 2008, 06:41 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Location: , , .
Posts: 125
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If the TextChanged event handler is public, you can just call it as mentioned above. By default, event handlers are private so you'll have to change that. You might consider writing a separate routine that your ListBox and the TextChanged event handler can both call.
Rod
Rod Stephens, Visual Basic MVP
RodStephens@vb-helper.com
*** New Book ***
"Visual Basic 2008 Programmer's Reference"
Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
|

October 7th, 2009, 07:54 PM
|
|
Registered User
|
|
Join Date: Sep 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to attach event listener to child IE window?
Hi
I used activex object to open the application in IE. That always opens ina new window. My requirement is that I need to attach event listener to that child window. I can make it close by calling quit method. But instead of window.attachEvent if I use Explorer.attachEvent then it throws error. Is there any way I can get control of the child window or a way i can open it in the same window and attach events?
Please help.
Part of my code is like below:
<Script LANGUAGE="JavaScript">
var Explorer;
function openIE()
{
Explorer = new ActiveXObject("InternetExplorer.Application");
Explorer.Navigate("http://google.com");
Explorer.Visible = true;
//Explorer.Quit();
}
function closeIE(Explorer)
{
Explorer.Quit();
}
function statusreport(){
alert("statusreport");
}
if (window.attachEvent)
{
window.attachEvent("onload", statusreport)
window.attachEvent("onkeypress", showit)
}
function showit()
{
alert("event.x: "+event.x)
alert("event.y: "+event.y)
}
document.onclick=showit;
</Script>
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |