Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ctrl-V pastes twice in RichTextBox

Posted on 1999-06-23
11
Medium Priority
?
1,285 Views
Last Modified: 2012-08-14
I have a RichTextBox on a form. I have edited the menu for Edit>>Paste to make Ctrl-V a shortcut. The problem is that when I use Ctrl-V, it pastes twice in succession. If I use Alt-E-P, or click, it pastes only once. If I disable the declarations for the Edit>>Paste_Click() sub, Ctrl-V will still paste, but Alt-E-P or click do not. I can eliminate Ctrl-V as a shortcut in the menu editor, and Ctrl-V still works; however, the user will not see Ctrl-V in the menu, or know it's a valid way to paste.

How do I stop the RichTextBox from pasting twice if I set Ctrl-V as a shortcut? I have noticed that WordPad, which also uses the RichTextBox, has Ctrl-V listed in the menu as a shortcut, but there is no problem with double-pasting. I have VB5.0, fixed with SP3, on Win95.
0
Comment
Question by:hddp666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 2

Expert Comment

by:SLE
ID: 1519384
CTRL-V has standard paste functionality in most controls. So I suggest you simply put the following code in the Paste_Click event:

SendKeys "^v"

Or am I missing the point here?

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1519385
Absolutely! SLE is right. Ctrl+V is already assigned to "Paste".

It is standard windows functionality, exactly like Shift+Ins, and right-clicking on a control and choosing "Paste" from the popup menu. Because it is standard windows functionality, you should NOT provide a menu yourself, simply assume the user knows how to do this.
0
 
LVL 1

Author Comment

by:hddp666
ID: 1519386
I know that ctrl-V is the standard paste function for most controls, and that it works fine for RichTextBox controls. However, I would like the menu to have this listed, as I cannot assume that the user will know this a priori. The present application doesn't matter, as it is an encryption utility for saving all of my usernames and passwords (I want to only have to ABSOLUTELY remember the encryption key).

I suppose I can trap the ctrl-V keypress event, and then call the paste sub. I will try this, and award if it works. However, I would really like to know how to fix this problem, so that any future programs will not need this kludge.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:caraf_g
ID: 1519387
"as I cannot assume that the user will know this a priori"

I think you can - it's standard windows functionality so you can assume the user learnt this when they learnt how to use Windows.
0
 
LVL 1

Author Comment

by:hddp666
ID: 1519388
caraf_g,

You obviously have never written software for general use before. I have had idiots call me up, looking for the "Any Key" because their computer is telling them to press any key to continue. One time, this moron was unable to delete files from the Explorer window because he couldn't keep his hand still while right-clicking and windows kept telling him that he couldn't move the icon. To assume that people will know what CTRL-V does "when they learn Windows...." is completely ludicrous, as most people NEVER "learn Windows."

0
 
LVL 1

Author Comment

by:hddp666
ID: 1519389
SendKeys "^v" does not trap the ctrl-V keypress, it sends it. If I use this code in the menu_click declaration, I still wind up with double pasting when I use ctrl-V. I already know I can remove ctrl-V as a shortcut from the menu, and get rid of the double-pasting. However, I want to be able to show ctrl-V on the menu as a shortcut, and not assume that the user is experienced.

This double-pasting problem does not exist for the regular TextBox control. I can show ctrl-V in the menu, and it will not double paste. This problem is specific to the RichTextBox, and maybe only for VB5.
0
 
LVL 2

Accepted Solution

by:
header earned 60 total points
ID: 1519390
You could set a boolean variable in the keypress event of the richtext box when ctrl-v is pressed.  Then in the Menu ctrl-v click event you could say, if the variable is true then the user pressed ctrl-v and you could exit sub.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1519391
hddp666

"You obviously have never written software for general use before"

LOL - I've been developing software for over ten years now in commercial applications. But I see from your profile that you have quite a lot of experience yourself. So let's not let this deteriorate into some silly slagging match.

I appreciate your sentiment about trying to make your software moron proof but I have to warn you. Even in the days of the great German philosophers they realised something like that just could not be achieved. I think it was Friedrich Nietzsche (?) who said "In the face of stupidity even the gods are powerless".

But never mind, you obviously have decided that you must have this menu option. And you're in good company - my Internet browser has it, Notepad.exe has it, and VB itself has it too, so in actual fact it must be some sort of standard.

Back to the question.

If you have to do something different for a rich text box, why not use the following method to determine whether you're on one:

If Me.ActiveControl Is Nothing Then
    'something's amiss - no current control selected
    Exit Sub
End If
If TypeOf Me.ActiveControl Is RichTextBox Then
    'do something different
End If

0
 
LVL 1

Author Comment

by:hddp666
ID: 1519392
Header, your answer is this: "You could set a boolean variable in the keypress event of the richtext box when ctrl-v is pressed.  Then in the Menu ctrl-v click event you could say, if the variable is true then the user pressed ctrl-v and you could exit sub."

I know I can do this sort of thing; I was going to do something like see if CTRL-V was pressed in Menu_Click, and if so, disable the paste declaration.

However, the answer I am looking for is a way to stop the RichTextBox from acting this way. The regular textbox does not do this double-pasting thing, even if it is in the menu_click declarations.

Do you know how to actually solve this RichTextBox problem, or is it endemic to VB5.0?
0
 
LVL 2

Expert Comment

by:header
ID: 1519393
I have never heard of this happening, it just seems like checking a variable would work.  Your question was, "How do I stop the RichTextBox from pasting twice if I set Ctrl-V as a shortcut?"  If my answer works, great!  Otherwise, reject it.

If you are dead set on finding another way, more power to you, I just don't see the point of going to the trouble if you already have another way of doing it.
0
 
LVL 1

Author Comment

by:hddp666
ID: 1519394
Header, I will try your answer and give you the points. I thought that maybe someone else had this problem, and there was a way to fix it, like an updated msvbvm50.dll, or some property I had overlooked. I know the VB5.0 RichTextBox control had other problems, like weird scrollbars, that were fixed by the VS_SP3 update.



0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question