Can't disable double-click in RichTextBox

J

JT

Hi,

I want to disable the ability to launch an application that is
embedded in the text of a RichTextBox control. I've seen various
posts that say that doing the following will disable click and double-
click processing:

base.SetStyle(ControlStyles.StandardClick, false);

That did not work.

I can't find a way to intercept the event and cancel it, as in
e.Cancel, like you can do in some event handlers. Many people have
complained that they can't get the double-click to work. Well, I
can't stop it from working.

Any clues?

Thanks,

JT
 
N

Nicholas Paldino [.NET/C# MVP]

JT,

The documentation for the ControlStyles enumeration says for the
StandardDoubleClick value that if the StandardClick style is false, then
that style is ignored.

I would call SetStyle with the StandardDoubleClick value to false.

If that doesn't work, I would say to override the OnDoubleClick method,
and call the base if you want to execute the normal double click handler,
however, I don't think in this case it will work.

Which leads me to the final recommendation, to override the WndProc
method and handle the WM_LBUTTONDBLCLK message, calling the base
implementation of WndProc if you want the default behavior.
 
J

JT

JT,

The documentation for the ControlStyles enumeration says for the
StandardDoubleClick value that if the StandardClick style is false, then
that style is ignored.

I would call SetStyle with the StandardDoubleClick value to false.

If that doesn't work, I would say to override the OnDoubleClick method,
and call the base if you want to execute the normal double click handler,
however, I don't think in this case it will work.

Which leads me to the final recommendation, to override the WndProc
method and handle the WM_LBUTTONDBLCLK message, calling the base
implementation of WndProc if you want the default behavior.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I want to disable the ability to launch an application that is
embedded in the text of a RichTextBox control. I've seen various
posts that say that doing the following will disable click and double-
click processing:
base.SetStyle(ControlStyles.StandardClick, false);
That did not work.
I can't find a way to intercept the event and cancel it, as in
e.Cancel, like you can do in some event handlers. Many people have
complained that they can't get the double-click to work. Well, I
can't stop it from working.
Any clues?

JT- Hide quoted text -

- Show quoted text -

Nicholas,

Thank you. Are you saying I should set StandardClick to true so that
I can set SandardDoubleClick to false? I will try all combinations of
that.

I already tried processing the DoubleClick event by adding that event
handler, meaning MyRichTextBox_DoubleClick(object sender, EventArgs
e). Is the OnDoubleClick method different from that or just a
different way of accessing the same thing?

I will look into the message processing.

JT
 
N

Nicholas Paldino [.NET/C# MVP]

JT,

OnDoubleClick is a protected virtual method which should handle the
WM_LDBLCLICK windows message. Right now, it only fires the event, which I
don't think is what you want, because it still processes the message, which
will end up executing the code.

I think overriding the WndProc method is the best bet, since you can
just disregard the message when it comes in.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

JT said:
JT,

The documentation for the ControlStyles enumeration says for the
StandardDoubleClick value that if the StandardClick style is false, then
that style is ignored.

I would call SetStyle with the StandardDoubleClick value to false.

If that doesn't work, I would say to override the OnDoubleClick
method,
and call the base if you want to execute the normal double click handler,
however, I don't think in this case it will work.

Which leads me to the final recommendation, to override the WndProc
method and handle the WM_LBUTTONDBLCLK message, calling the base
implementation of WndProc if you want the default behavior.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I want to disable the ability to launch an application that is
embedded in the text of a RichTextBox control. I've seen various
posts that say that doing the following will disable click and double-
click processing:
base.SetStyle(ControlStyles.StandardClick, false);
That did not work.
I can't find a way to intercept the event and cancel it, as in
e.Cancel, like you can do in some event handlers. Many people have
complained that they can't get the double-click to work. Well, I
can't stop it from working.
Any clues?

JT- Hide quoted text -

- Show quoted text -

Nicholas,

Thank you. Are you saying I should set StandardClick to true so that
I can set SandardDoubleClick to false? I will try all combinations of
that.

I already tried processing the DoubleClick event by adding that event
handler, meaning MyRichTextBox_DoubleClick(object sender, EventArgs
e). Is the OnDoubleClick method different from that or just a
different way of accessing the same thing?

I will look into the message processing.

JT
 
J

JT

JT,

The documentation for the ControlStyles enumeration says for the
StandardDoubleClick value that if the StandardClick style is false, then
that style is ignored.

I would call SetStyle with the StandardDoubleClick value to false.

If that doesn't work, I would say to override the OnDoubleClick method,
and call the base if you want to execute the normal double click handler,
however, I don't think in this case it will work.

Which leads me to the final recommendation, to override the WndProc
method and handle the WM_LBUTTONDBLCLK message, calling the base
implementation of WndProc if you want the default behavior.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I want to disable the ability to launch an application that is
embedded in the text of a RichTextBox control. I've seen various
posts that say that doing the following will disable click and double-
click processing:
base.SetStyle(ControlStyles.StandardClick, false);
That did not work.
I can't find a way to intercept the event and cancel it, as in
e.Cancel, like you can do in some event handlers. Many people have
complained that they can't get the double-click to work. Well, I
can't stop it from working.
Any clues?

JT- Hide quoted text -

- Show quoted text -

Okay, I tried all combinations of StandardClick and
StandardDoubleClick and that made no difference.

I also tried overriding the WndProc method by checking for the
WM_LBUTTONDBLCLK message (setting it to 0x0203, as found in WinUser.h
and various other files) but this didn't even catch the message when I
double-clicked. My approach was to only call the base.WndProc() if
the message did not match the double-click. Would that have been
right? Did I need to trap a message specifically dealing with the
object clicked on instead of the rich text box?

Thanks,

JT
 
P

Peter Duniho

Per your request, I've taken a closer look at this thread. Not sure if
you're going to find my input useful at all. But you did ask. :)
I want to disable the ability to launch an application that is
embedded in the text of a RichTextBox control.

Perhaps you could be more clear about what that means. Maybe for
someone who does RTF stuff all the time it's obvious, but I don't know
how you embed an application in the text of a RichTextBox control.

As is almost always the case, it would be helpful if you could provide a
concise-but-complete example of code that demonstrates the problem
you're having.

My second thought is that I'm not at all clear that disabling
double-clicking is going to be the right way to deal with this. It's
hard to say for sure, since I obviously don't really understand the
original problem anyway. But note that disabling double-clicking
generally for the control means that you not only have prevented some
specific behavior that (for some reason) you don't want, you also wind
up preventing other behavior that users will expect to work correctly.

This goes hand-in-hand with my previous comment about not playing cowboy
with generally accepted rules of UI design. :)

So, it might be worth exploring other ways to disable this behavior,
than the broad-reaching technique of disabling double-clicks altogether.

That said, it sure seems like it should be possible to disable
double-clicks. But without a good example of the situation you're
trying to prevent, it's difficult to comment on what techniques might work.

Pete
 

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