how to "see" click event from a usercontrol

J

JohnR

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 "usercontrol 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 "usercontrol click fired". However, if I click somewhere in
WSToolBarButton but not in the button I do get "usercontrol 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 "usercontrol 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.UserControl
#Region " Windows Form Designer generated code " <snip>
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs) Handles MyBase.Click
MsgBox("wstoolbarbutton 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 WsToolbarButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles WsToolbarButton1.Click
MsgBox("usercontrol click fired")
End Sub
 
C

Cor Ligthert

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/microsoft.public.dotnet.languages.vb/msg/f1108cb1295fd1e1?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/microsoft.public.dotnet.languages.vb/msg/c0b9e5f63c24b4af?hl=en

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

JohnR said:
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.
 
J

JohnR

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
 
J

JohnR

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
 
C

Cor Ligthert

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
 
C

Cor Ligthert

Herfried,

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
 
D

Debbie Carter

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
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
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.
 
C

Cor Ligthert

Debbie,
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.

Please tell me what is wrong in this message. I myself see beside some
commas and the wrong spelled word "opinion" not many errors.

Therefore, I will be pleased when you show it me.

I have not made this as something to describe, however too Herfried, who
knows all the used keywords and classes.

Now your message is only offending for me and does not give any help.

Have you thought about the fact, that it is maybe something, what I do as
well in Dutch, when I write quickly a message and than try to correct the
errors and do it than wrong?

I have seen often writing errors in my message. However for me is it a
newsgroup message, not a document.

Cor
 
C

Cor Ligthert

Herfried,

First of all, good nicely done answer, there is in my opinion not much to
bring up against it and gives me a good idea what you was meaning.

However, what is the difference when we use three separated buttons instead
of a groupbox with three included buttons.

I will remember this. (I was myself not aware of that). This means for me
that using a toolbar has an extra's advantages above that as I saw it, what
was uniformity.

Cor
 
D

Debbie Carter

Cor,
I did not say anything about spelling mistakes or commas as we all get
in a hurry and make them while writing on the computer. I was talking about
missing words and the sentences not making sense. I read your messages
everyday and they are very helpful when I can understand them. Sometimes I
have to read them 3 or 4 times to know what you are talking about. I just
thought I would help you like you help everyone else. Please read the
corrections below.
Please tell me what is wrong in this message.

Please tell me what is wrong with my message.
I myself see beside some commas and the wrong spelled word "opinion" not
many errors.

I can only see some missing commas and the word "opinion" spelled wrong.
Therefore, I will be pleased when you show it me.

Therefore I would be pleased if you showed me.
I have not made this as something to describe, however too Herfried, who
knows all the used keywords and classes.

Sorry...can not figure this one out. I think I know what it is saying but
not sure.
Now your message is only offending for me and does not give any help.

Your message offends me and does not provide any help.
Have you thought about the fact, that it is maybe something, what I do as
well in Dutch, when I write quickly a message and than try to correct the
errors and do it than wrong?

Not sure what this sentence is saying...I think you are telling me you are
Dutch?
I have seen often writing errors in my message. However for me is it a
newsgroup message, not a document.

I make wrtiting errors often but since this is a newsgroup and not a
document I don't really care.

Hope this helps,
Debbie
 
C

Cor Ligthert

Debbie,

I agree however as well disagree with you, but your message is helpful. My
English is based on how I have learned English not American.

To check that, I took just one message from Terry Burns. He is from Thames
Valley, not far away from Oxford where for us Dutch the best English is
spoken.
Ctrl Alt J will open up the object browser, and you can find all the
classes
in your assembly

When I understand your message well, than you would have written something
as.
Ctrl Alt J opens the object browser and you find than all the classes in
your assembly

I have learned to do it in the way as Terry writes. While by instance, the
way you write, looks very much on grammatical Dutch. Maybe you think that it
is therefore easier for me. No when I write English, I am thinking in
English. It can be that I overdo it now and therefore I will keep an eye on
it in future and am thankful for your message.

The sentence about Dutch was that I skip in Dutch as well many words when I
quickly write a message. I am busy with the next sentence when the first is
not even ready. Than I correct it, however set than the words in the wrong
sequence. A message like yours is than good to point me again on that.

However, I wrote first "...that I am skipping in Dutch as well many words
when I am writing quickly". Now I changed it, so maybe your message has
success and let me write in a more popular way in this newsgroup.

The message concerning Herfried was that I was using more for us both known
keywords than language. Because Herfried understands those keywords, has it
less sense to write it in a way that everybody understands it. Maybe I
unconscious think too much, that because Herfried understands as much
languages as I, that the correct grammatical use is less important. You are
right when you now want to tell that more people read those messages, but
sometimes it gives than in my opinion a too long messages to explain
everything and is than for Herfried without any sense.

The "when/if" error is something somebody else showed me as well. That is an
error hard to overcome. While grammatical in Dutch, it is as well not
correct, are we using that often and therefore I probably make that error in
English as well quiet easy, even if I keep an eye on it (I wrote first
"when"). :)
I make wrtiting errors often but since this is a newsgroup and not a
document I don't really care.

I do not understand what you want to tell me with this last sentence from
you. However, the last part is not true. I don't care about it in the same
way as if it was a document.

:)

Thank you

Cor
 
D

Debbie Carter

Hello Cor,
Since this is a programming newsgroup I will drop the subject but
thank you for explaining. I was unaware the English language had different
versions. Keep up the good work!
Debbie
 
D

Doug Taylor

Hello Cor,
Since this is a programming newsgroup I will drop the subject but
thank you for explaining. I was unaware the English language had different
versions. Keep up the good work!
Debbie
Are trying to start a flame war :) Even English as spoken in England
has many dialects, some almost impossible to understand to non native
speakers, such as Gorbals Glaswegian English. I have worked with many
people from the Netherlands and they in general speak and write
excellent English.

Doug Taylor
 
J

JohnR

Hey Cor,

My Father was born in Rotterdam just before the war. He came over to the
USA in his late 20's. Unfortunately my Mother was not Dutch and so no Dutch
was spoken in my home, so I can't speak a word of it.

Funny thing, though. I can recognize a Dutch accent a mile away. I was
in a train in New York during the marathon and over heard some people
talking in the next row. I asked them if they were speaking Dutch and they
were amazed that I recognized it. It's such a relatively small country that
not many people would know what it was.

Even funnier was during a convention I attended. I was introduced to an
oriental person, and to my surprise when he spoke english I immediately
recognized that he had a heavy Dutch accent. Now, let me tell you, I don't
meet very many oriental people who speak english with a Dutch accent, so I
was completely blown away.... He explained that his Father was transfered
to Holland from China and he was born in Holland, and Dutch was actually his
native language!!! Now go figure that one out...

John
 
C

C-Services Holland b.v.

JohnR said:
I asked them if they were speaking Dutch and they
were amazed that I recognized it. It's such a relatively small country that
not many people would know what it was.

We Dutch are the chinese of the west :) Find any remote location where
there's only a handfull of foreigners and I'll bet you 10:1 that one of
them is Dutch :p

I've been around the world and when I finally thought I was away from my
countrymen.. there would be one there..haha
 
S

Stephany Young

I think that everyone is missing the point here.

Regardless of what language you are writing in - if the reader doesn't
understand the message then you have wasted your time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top