Dear all:
I have a problem about how to handle the events. For example, there
are two forms, Form1 and Form2. Form2 is owned by Form1 and there is a
button,Button1, in Form2. It is no problem for Form2 to handle the
event "Button1.Cl ick" . My problem is how to handle the Button1.click
event in Form1 as Form2's owner. Is there any way to achieve this
demand???
=============== =============== =============== =============== =====
owner and owned form relationship what i mean is Below :
Me.AddOwnedForm (Form2) 'Me is Form1 instance
Form2.Show()
thx for your suggestion and reply
Jerry Wei 3 1804
Hi,
Use addhandler.
Dim frm As New Form2
frm.Owner = Me
frm.Show()
AddHandler frm.Button1.Cli ck, AddressOf buttonclick
Private Sub ButtonClick(ByV al sender As System.Object, ByVal e As
System.EventArg s)
MessageBox.Show ("ME")
End Sub
Ken
-------------------------
"Jerry Wei" <en*********@ya hoo.com.tw> wrote in message
news:25******** *************** ***@posting.goo gle.com...
Dear all:
I have a problem about how to handle the events. For example, there
are two forms, Form1 and Form2. Form2 is owned by Form1 and there is a
button,Button1, in Form2. It is no problem for Form2 to handle the
event "Button1.Cl ick" . My problem is how to handle the Button1.click
event in Form1 as Form2's owner. Is there any way to achieve this
demand???
=============== =============== =============== =============== =====
owner and owned form relationship what i mean is Below :
Me.AddOwnedForm (Form2) 'Me is Form1 instance
Form2.Show()
thx for your suggestion and reply
Jerry Wei
Jerry,
Here is one approach:
Private Sub OpenForm2Button _Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles OpenForm2Button .Click
Dim newForm2 As New Form2()
newForm2.Show()
' Associate the HandleForm2Butt on1Click Sub in this form with
' newForm2's Button1 click event.
AddHandler newForm2.Button 1.Click, AddressOf HandleForm2Butt on1Click
End Sub
' This Sub in Form1 will now handle a click on Button1 on Form2.
Private Sub HandleForm2Butt on1Click(ByVal sender As Object, ByVal e As System.EventArg s)
MessageBox.Show ("You clicked Button1 on Form2")
End Sub
This example assumes Form1 has a button named OpenForm2Button . When the button is clicked the OpenForm2Button _Click Sub instantiates and shows Form2. It also associates a Sub in Form1 with Form2's Button1 click event.
--
Mike
Mike McIntyre
Visual Basic MVP www.getdotnetcode.com
"Jerry Wei" <en*********@ya hoo.com.tw> wrote in message news:25******** *************** ***@posting.goo gle.com... Dear all: I have a problem about how to handle the events. For example, there are two forms, Form1 and Form2. Form2 is owned by Form1 and there is a button,Button1, in Form2. It is no problem for Form2 to handle the event "Button1.Cl ick" . My problem is how to handle the Button1.click event in Form1 as Form2's owner. Is there any way to achieve this demand??? =============== =============== =============== =============== ===== owner and owned form relationship what i mean is Below : Me.AddOwnedForm (Form2) 'Me is Form1 instance Form2.Show() thx for your suggestion and reply Jerry Wei
Jerry,
You should not even have to know the owner, just set a public event in your
form2. Raise it in the buttonclick, and catch it in form1.
Something like this
\\\Form1
Friend WithEvents frm As New Form2
Private Sub Button1_Click(B yVal sender _
As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click
frm.Show()
End Sub
Private Sub Buttonform2_Cli ck(ByVal sender _
As System.Object, ByVal e As System.EventArg s) Handles frm.myevent
MessageBox.Show (DirectCast(sen der, Button).Name & " I am pushed")
End Sub
///
\\\Form2
Friend Event myevent(ByVal sender As System.Object, _
ByVal e As System.EventArg s)
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
Button1.Name = "buttonform 2"
RaiseEvent myevent(sender, e)
End Sub
///
I hope this helps?
Cor
"Jerry Wei" <en*********@ya hoo.com.tw> Dear all: I have a problem about how to handle the events. For example, there are two forms, Form1 and Form2. Form2 is owned by Form1 and there is a button,Button1, in Form2. It is no problem for Form2 to handle the event "Button1.Cl ick" . My problem is how to handle the Button1.click event in Form1 as Form2's owner. Is there any way to achieve this demand??? =============== =============== =============== =============== ===== owner and owned form relationship what i mean is Below :
Me.AddOwnedForm (Form2) 'Me is Form1 instance Form2.Show()
thx for your suggestion and reply Jerry Wei This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil B Brubaker |
last post by:
I'm trying to create my own shellexecute program named shell4OD and am
having problems with handles. Here is my code ...
=====
Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As _
String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public function Shell4OD( byVal cmd as string, byVal...
|
by: Wade Chy |
last post by:
Hi All
I am in a situation where I have to grant select privileges on tables
owned by a different owner to a specific role. I am logged in as
system/sysdba. I have created a new role FIN_READ_ONLY. I need to
grant SELECT privileges on all the existing and future tables owned by
FIN. I tried to grant SELECT on FIN.ACCT_REF to FIN_READ_ONLY. But was
not successful due to insufficient privileges since SYSTEM does not
own the table or dont...
|
by: Crucifix |
last post by:
Hello,
I'm writing a small C# app, and part of what I'm trying to do
involves the dragging of PictureBox controls on a form. Unfortunately,
MouseMove seems to be behaving very oddly, causing spurious MouseMove
events when the cursor doesn't actually move. I've looked for a
solution in the groups, and although I've come close, I haven't found a
proper explanation or fix. Here is a rundown, followed by a very
simple test app that...
|
by: Ioannis Demetriades |
last post by:
Hi
On my main form I have a menu with menu shortcuts and I noticed that when I
display a new form as an MDIChild form the shortcuts work fine from within
the mdi child form. If however i display an owned form (as opposed to
mdichild) the shortcuts don't work unless the owner form has the focus.
Is there an easy way of making those shortcuts work with owned forms as
well?
|
by: Dean Slindee |
last post by:
I would like to show an owned form at a predetermined spot on the screen
relative to the the owner form's position on the screen (example:
frmOwner.Top + 100 and frmOwner.Left + 50). How to do?
Thanks,
Dean Slindee
| |
by: Adam J. Schaff |
last post by:
I have noticed that if a user closes a form via pressing return (either
while the OK button has focus or if AcceptButton is set to OK for the form)
then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad
for me, because in my application, Form1 responds to an ENTER keypress by
calling Form2. If the user closes Form2 via an ENTER, then Form1 just
reopens it again, kind of trapping the user in Form2 (they can still close...
|
by: travismorien |
last post by:
I hope there is an easy way to do this...
I'm doing a database which keeps track of things that people or
entities (entities = trusts and companies) own, among other things.
When assets are owned by individuals, its easy. I have a table listing
the various assets, a table listing the various people and entities and
a third table with the IDs of the people/entities and the IDs of the
assets they own.
|
by: pamelafluente |
last post by:
Hi guys I am puzzed (???) with a probably stupid problem (VB2003). I
must be doing something dumb ...
I want to open a owned form (must *not* be mdi child) over an Mdi
Container, when the Mdi container starts.
I have a small demo program made of: Form1, Form2 (empty) and a
"StartProgram" class
which contain the following code. The startup object is set to be: Sub
Main
|
by: =?Utf-8?B?SkI=?= |
last post by:
I would like to create an owned form that is owned by a modal dialog rather
than a modeless form. The idea is the following
Dim dlg as new Mydlg
with dlg
.ShowDialog
.Dispose
end with
class mydlg
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |