473,700 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to "see" click event from a usercontrol

In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based on some
initialization information obtained elsewhere. Basically, I'm going to
create my own dynamic toolbar where the toolbarbuttons can change. I'm not
using the VB toolbar because of limitations in changing things like
backcolor (I can't get it to change, but that's another story).

For testing purposes I simply dragged a copy of WSToolBarButton from the
usercontrol toolbox to the form. I set up a sub to handle the click event
of the WSToolBarButton . This sub displays a messagebox "usercontro l click
fired". The problem is that the click event is fired only when I click
somewhere in WSToolBarButton but NOT in the button that is part of
WSToolBarButton . If I click on the button nothing happens.

So, I went into the code for WSToolBarButton and set up a click event for
the button which display a msgbox "button click fired". Running the
program if I click the button I get "button click fired" and that's all. I
don't get "usercontro l click fired". However, if I click somewhere in
WSToolBarButton but not in the button I do get "usercontro l click fired".

My question is how exactly can I set up WSToolBarButton so that if a user
clicks anywhere within the control I will execute the click event of the
MYUSERCONTROL (the one that says "usercontro l click fired") . I guess I
somehow have to fire the WSToolBarButton click event from within the button
click event but I just don't know how to set it up. I've played with
RAISEEVENT but had no luck at all. I tried calling the
WSToolBarButton _Click sub directly from the Button click event sub, but it
doesn't bubble up to the click event on the main form.

I'm totally out of ideas here... Can anybody explain what I would need to
do to get this to work? I've attached the code snippets at the end of the
msg.

Thanks,
John
*************** ****** this code is in my usercontrol
*************** *************
Public Class WSToolbarButton
Inherits System.Windows. Forms.UserContr ol
#Region " Windows Form Designer generated code " <snip>
#End Region
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
MsgBox("button click fired")
WSToolbarButton _Click(sender, e)
End Sub

Private Sub WSToolbarButton _Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Click
MsgBox("wstoolb arbutton click raised")
'at this point the click event for this usercontrol on the main form
is fired ONLY IF this routine was caused
'by clicking the WSToolBarButton somewhere other than the button. If
this routine was called from the
'button1_click routine the click event for this usercontrol on the
main form WILL NOT execute.
End Sub
End Class

*************** *** this code is from my main form
*************** ************
Private Sub WsToolbarButton 1_Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles WsToolbarButton 1.Click
MsgBox("usercon trol click fired")
End Sub
Nov 21 '05 #1
41 4303
John,

Normally do you have too use the select case to find what button is clicked.
I use it with a tag and than like in this message.
http://groups-beta.google.com/group/...295fd1e1?hl=en

This is a complete different solution posted by Herfried, that I found very
nice (when the above cannot be used because this one cost of course much
more processing time).
http://groups-beta.google.com/group/...3c24b4af?hl=en

I hope this helps,

Cor
Nov 21 '05 #2
"JohnR" <Jo******@hotma il.com> schrieb:
I'm not using the VB toolbar because of limitations in changing things
like backcolor (I can't get it to change, but that's another story).


Although this is, as you say, another story, it's very easy to change a
toolbar's background color: Set the control's 'Appearance' property to
'Flat' and change the backcolor of the container the toolbar is placed in.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Hi Herfried,

I successfully changed the background color of the toolbar, however it
still seems VERY restrictive in what you can do in terms of formatting it.
For example, could you tell me if the following is possible (and if it is,
how to do it?).

1. change the spacing between buttons for a more user pleasing appearance
2. change the background color of the actual button to have it slightly
standout against the toolbar background color
3. put a border around the button, again to give it a more pleasing
appearance
4. increase the width of a button designated as a 'separator' style (as a
way to space the real buttons a little wider).

Seems like microsoft hard coded (or hid) a lot of the properties and methods
that are needed to make the toolbar and it's buttons easy to format. This
is the main reason why I wanted to create my usercontrol (composed of a
button and label) and simulate my own toolbar. It will be much more
flexible than using the MS toolbar.

Given that, I still have my original problem... If I create my usercontrol
consisting of a button, for example, if the user clicks on the button how
can I propagate the click event so that it appears that the user clicked on
my usercontrol (see original post for code snippets).

If you or anybody else can explain this to me I would be very grateful.

Thanks,
John

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uz******** *****@TK2MSFTNG P10.phx.gbl...
"JohnR" <Jo******@hotma il.com> schrieb:
I'm not using the VB toolbar because of limitations in changing things
like backcolor (I can't get it to change, but that's another story).


Although this is, as you say, another story, it's very easy to change a
toolbar's background color: Set the control's 'Appearance' property to
'Flat' and change the backcolor of the container the toolbar is placed in.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Hi Cor,

I do plan on using some method of determining what button was clicked, but
before that I need to be able to pass the click event (when the user clicks
on the button in my usercontrol) to simulate the user clicking the actual
usercontrol (see orig post for code snippets). Surely there must be a way
to do this... If you can point me to a solution I would appreciate it very
much.

Thanks,
John

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Ow******** ******@TK2MSFTN GP09.phx.gbl...
John,

Normally do you have too use the select case to find what button is
clicked.
I use it with a tag and than like in this message.
http://groups-beta.google.com/group/...295fd1e1?hl=en

This is a complete different solution posted by Herfried, that I found
very nice (when the above cannot be used because this one cost of course
much more processing time).
http://groups-beta.google.com/group/...3c24b4af?hl=en

I hope this helps,

Cor

Nov 21 '05 #5
John,

I looked (not readed) your reply to Herfried as well.

Why don't you go to a usercontrol made from a groupbox and individual
buttons.
In my opinion gives that you much more freedom.

Just my thought,

Cor
Nov 21 '05 #6
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
I looked (not readed) your reply to Herfried as well.

Why don't you go to a usercontrol made from a groupbox and individual
buttons.
In my opinion gives that you much more freedom.


I don't think that creating a windowed control for each of the buttons is a
good idea because windows are costly objects:

Windows are not cheap objects
<URL:http://blogs.msdn.com/oldnewthing/archive/2005/03/15/395866.aspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Herfried,

Windows are not cheap objects
<URL:http://blogs.msdn.com/oldnewthing/archive/2005/03/15/395866.aspx>

--

In my opinion cheaper than painting yourself everything and create events
based on that.

When the Op needs a special button bar, what you know is a nice however very
limited control, than I think the groupbox with buttons is a way to go. I
thought even to remember me that you had written that yourself once as well.
(Not that that is my source for my answer).

When I look at the article you provide I have to think on menu items, which
in my opinon are based on the principle to add a lot of objects to another
object. Those menu items have AFAIK not much less functionality in them than
a button that I suggest to add to a groupbox.

However when you have a really better alternative, than I am as well very
curious to see that.

Cor
Nov 21 '05 #8
Cor,

Have you ever considered taking a course in the English language in your
spare time? Please don't be offended but your sentences are so mixed up
sometimes that they are hard to understand.

Hope this helps!

Debbie


Nov 21 '05 #9
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
Windows are not cheap objects
<URL:http://blogs.msdn.com/oldnewthing/archive/2005/03/15/395866.aspx>
In my opinion cheaper than painting yourself everything and create events
based on that.


The implementation might be cheaper in terms of implementation effort, but
the toolbar will require much more memory if every button is a separate
instance of a Win32 window class. Instances of window classes are costly in
memory. Raymond Chen, who wrote the article I referenced above, IIRC
mentioned the sample of a listbox control: If every item would be a
separate control (= window), the whole listbox control would occupy a huge
amount of resources, which is not desirable. Menus, for example, toolbars
and many other controls in Windows are not implemented as composite controls
for that reason, even if that would be "easier".
When the Op needs a special button bar, what you know is a nice however
very limited control, than I think the groupbox with buttons is a way to
go. I thought even to remember me that you had written that yourself once
as well. (Not that that is my source for my answer).
I don't remember that I have written that in the past.
When I look at the article you provide I have to think on menu items,
which in my opinon are based on the principle to add a lot of objects to
another object. Those menu items have AFAIK not much less functionality in
them than a button that I suggest to add to a groupbox.


The menu items actually don't have less functionality, but they require less
resources because they are not implemented as a set of separate windows (a
single window for each item). My comment only applies if the toolbar
contains more than n buttons -- if your toolbar only consists of three
buttons, implementing the toolbar the way I suggest is not worth the effort.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1666
by: MLH | last post by:
I used the following SQL to create a new table in a database on a remote MySQL server by copying one already there. I know the table exists SOMEWHERE in cyberspace. I can read its data, write to it, delete from it. But I cannot see it. The only way I know it exists is by running this SQL from Access 97 pass through query: SELECT ALL new_tbl.name FROM new_tbl The database resides on a MySQL server that was created with a single table...
3
2369
by: Lou | last post by:
I created a small database and defined a simple table with about 12 columns. To load the table I imported data from a text file. I got a successful message after importing the data; no error messages at all. However, when I try to get a sample of the database, nothing comes up. I only the the columns I defined, but no rows at all. What did I do wrong? I'm using Personal DB2 8.1. Thanks for your help. Luis
3
3429
by: sql-db2-dba | last post by:
When I did db2batch to benchmark a query, it performance details came back with this reading ... "High water mark for database heap = 4291373408" Does this mean it would have caused memory thrashing at the server? Did I over-allocate resources. We just increased BuffPage to 16384 from its default of 1000. Pagesize of the bufferpool was of course set to -1 so it would use the DBM cfg
2
3574
by: MLH | last post by:
I used the following SQL to create a new table in a database on a remote MySQL server by copying one already there. I know the table exists SOMEWHERE in cyberspace. I can read its data, write to it, delete from it. But I cannot see it. The only way I know it exists is by running this SQL from Access 97 pass through query: SELECT ALL new_tbl.name FROM new_tbl The database resides on a MySQL server that was created with a single table...
0
1403
by: GS | last post by:
Documentation states that there supposed to be a "Data Sources" windows in VS 2005. See below. I can not find Data menu in VS 2005 anywhere. Anybody sees that menu? Opening the Data Sources Window You display the Data Sources window by clicking Show Data Sources on the Data menu. The Data menu is only available when a project is open in Visual Studio.
2
1930
by: zacks | last post by:
I use some shareware CD/DVD burning software that has a command line interface version. This allowed me to write my own custom SDK that performs various CD/DVD burning operations from my own VB.NET applications. Recently, I had some problems reading DVDs that I had recently burned, reading them with the same DVD device that burned them. So I wrote a quickie verification program that simply attempts to binary read all files on the disk.
3
1449
by: Michel Firholz | last post by:
Hi Group experts, i would like to tweak a javascript diashow with a bit SEO. No spamming, just ensuring the images are found. If the visitor is googlebot, it should not present the diashow, but all images in one file... Now i have a doubt: can the cooglebot even "see" anything from javascript generated pages? Thanks for your help.
10
3348
by: giannis | last post by:
How can i know ("see") the next record using the BindingSource without move to the next record ?
11
6179
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
0
8642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9209
Oralloy
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...
0
9069
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8964
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,...
0
7804
agi2029
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...
1
6558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5900
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();...
0
4400
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...
1
3085
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.