p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2008, 01:40 AM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old March 14th, 2008, 11:07 AM
Rod Stephens's Avatar
Wrox Author
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 125
Thanks: 0
Thanked 0 Times in 0 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 15th, 2008, 12:50 AM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old March 15th, 2008, 12:53 AM
Authorized User
Points: 152, Level: 3
Points: 152, Level: 3 Points: 152, Level: 3 Points: 152, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old March 15th, 2008, 06:41 PM
Rod Stephens's Avatar
Wrox Author
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 125
Thanks: 0
Thanked 0 Times in 0 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old October 7th, 2009, 07:54 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 4
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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 11: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 01:02 AM
Can't fire button event more than 1 time goatstudio ASP.NET 2.0 Basics 4 September 22nd, 2004 08:45 AM



All times are GMT -4. The time now is 07:29 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc