Wrox Programmer Forums
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 14th, 2008, 12:40 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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


 
Old March 14th, 2008, 10:07 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

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
 
Old March 14th, 2008, 11:50 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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?

 
Old March 14th, 2008, 11:53 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

remember that mylistbox is in a dll (which was created by myself)

 
Old March 15th, 2008, 05:41 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

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
 
Old October 7th, 2009, 06:54 PM
Registered User
 
Join Date: Sep 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get Edit Template event to fire zoltac007 ASP.NET 2.0 Professional 4 February 13th, 2007 03:29 PM
Unable to fire a click event rfinks ASP.NET 1.0 and 1.1 Basics 2 September 1st, 2006 10:26 PM
SelectedIndexChanged Event doesn't fire ddudley3 ASP.NET 2.0 Professional 7 February 6th, 2006 10:47 AM
Pressing Enter should fire an event r_ganesh76 ASP.NET 1.0 and 1.1 Professional 4 September 28th, 2004 12:02 AM
Can't fire button event more than 1 time goatstudio ASP.NET 2.0 Basics 4 September 22nd, 2004 07:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.