|
Prev: Read Cannot
Next: saving all data on form
From: jp2msft on 5 Jul 2008 12:42 Thanks, Mr. Williams. You have given me a lot of ideas to work on. I really appreciate it! "Mike Williams" wrote: > "Mike Williams" <mikea(a)whiskyandCoke.com> wrote in message > news:e6oFp5l3IHA.5112(a)TK2MSFTNGP03.phx.gbl... > > .. . . one final thing, I inadvertently left the code "Caption = Len(s1)" in > the txtSubClass_Change event. I was using that purely for test purposes and > it serves no actual purpose in the working project, so you can get rid of > it. > > Mike > > > >
From: Mike Williams on 5 Jul 2008 13:25 "jp2msft" <jp2msft(a)discussions.microsoft.com> wrote in message news:9DB587FE-9652-45E3-A0DC-2D8CF65168D8(a)microsoft.com... > Thanks, Mr. Williams. You have given me a lot of > ideas to work on. I really appreciate it! You're very welcome. But before you go, have a look at the post in this thread by Bob Butler in which he points out that the top level menu item (Edit, in this case) actually does have a click event (something which I had missed) and so the code I posted can be simplified quite a lot because it no longer needs the subclassing. Also have a look at my response to Bob's post for more example code. Mike
From: jp2msft on 7 Jul 2008 10:05
This looks like a much simpler way of handling menu items. Thanks to both Mr. Butler and Mr. Williams for their insight into this problem. "Mike Williams" wrote: > "Bob Butler" <noway(a)nospam.ever> wrote in message > news:Of9fGSq3IHA.2580(a)TK2MSFTNGP06.phx.gbl... > > > No need to subclass; you can do the enable/disable > > of the subitems in the Click event of the top-level menu. > > That fires before the menu displays. > > Well, well, well! We live and learn :-) I created a Form and used the menu > editor to create various menus with sub menus, including a menu called Edit > with sub menus Copy and Paste. I then (in the IDE) clicked (and sometimes > double clicked) the various menu items so that VB brought up the code window > when I did so and created the "event wrapper" for me to place code in. When > I clicked (or double clicked) the main menu item (in this case, the Edit > menu) in the IDE VB did not react at all and so I just assumed, without any > further checking, that there were no click events for top level menus and I > therefore decided that I would need to subclass in order to get at that > event, which I did! I should have checked further of course and I would > probably have found the top level menu Click event, but I did not :-( > Thanks for putting me right on that one, because it simplifies the code > quite a lot, removing the need for subclassing as it does. > > Mind you, having said that, the basic idea of course remains the same and it > is still very sound, except you just remove the code I previously had in the > txtSubClass_Change event and place it instead in the mnuEdit_Click event. So > we don't need the module and we can simplify the Form code to something like > the following: > > Mike > > Option Explicit > Private Sub mnuCopy_Click() > Clipboard.SetText Me.ActiveControl.SelText, vbCFText > End Sub > > Private Sub mnuPaste_Click() > Me.ActiveControl.SelText = Clipboard.GetText(vbCFText) > End Sub > > Private Sub mnuEdit_Click() > Dim s1 As String > If TypeOf Me.ActiveControl Is TextBox Then > If Me.ActiveControl.SelLength > 0 Then > mnuCopy.Enabled = True > Else > mnuCopy.Enabled = False > End If > s1 = Clipboard.GetText(vbCFText) > If Len(s1) > 0 Then > mnuPaste.Enabled = True > Else > mnuPaste.Enabled = False > End If > Else > ' a textBox is not the current control, and we are > ' dealing only with TextBoxes in this simple example > mnuCopy.Enabled = False > mnuPaste.Enabled = False > End If > End Sub > > |