Show several tooltips at the same time (DevExpress) - c#

I am working on a C# WinForm application in Visual Studio 2008 and are using DevExpress.
I have added shortcuts to Some of the buttons (DevExpress SimpleButton) which triggers a button click (CTRL + R, CTRL B and so on...). I would like to show the shortcut texts in a tooltip next to each button when the user press and hold the CTRL key.
I have tried to use the DevExpress control 'ToolTipController' and that works OK if I only have one tooltip. But I would like to show more than one tooltip at a time. It seems like only the last tooltip that is added is shown.
Is it possible to show more than one tooltip at a time? Or does anyone have any other suggestion on how to solve this problem?

I solved this by creating a WPF control that looks similar to a standard tooltip (small box with a label). I then did an override on ProcessCmdKey and OnKeyUp on my form to listen to CTRL key down and key up.
When the user presses and holds down the CTRL key I loop through all my controls that has a shortcut and creates a WPF control on top of that control. For each WPF control I set the corresponding shortcut text. When the CTRL key is released I remove all WPF controls in OnKeyUp.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ if ((msg.Msg == WM_KEYDOWN) && ModifierKeys == Keys.Control && !_isKeyDown)
{
_isKeyDown = true;
ShowShortCutToolTips();
this.Focus();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if(e.KeyValue == 17 || e.Control) // 17 = Control Key
{
_isKeyDown = false;
HideShortCutToolTips();
}
}

Related

Shift + F10 in TextBox KeyDown event

I have a form with a text box.
myTB.KeyDown += new KeyEventHandler(this.myTB_KeyDown);
In this event I can get Keys.Apps to open the context menu.
Now another shortcut for context menu is Shift + F10.
Is it possible to capture that too inside the KeyDown event?
Any logic that I can implement to capture those keys?
So far what I see is, when the Shift key is pressed, that time itself the KeyDown event get's called and no way checking for both Shift and F10 together!
If I understand your question correctly, and you want to disable default Shift+F10 menu and handle those combination yourself, it's enough to handle KeyDown event and detect the combination and the set e.Handled=true;:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode== Keys.F10 && e.Shift==true)
{
//Shift + F10 pressed, do what you need.
e.Handled = true;
}
}
You can also disable the default context menu that will be shown, by setting ShortcutsEnabled property of your TextBox to false.
Here is a pretty safe way to check for shift + F10
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.F10 | Keys.Shift))
{
if (txtBox1.Focused)
{
txtBox1.Text = "Captured!";
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
Description:
This will capture every keystroke. From there is will check if the keystroke is Shift+F10, the single pipe acts like &&. After that it does a simple check to see if the textbox you are planning on having the event happen is focuses, or active control. If it fails either of those checks it sends the information of the keystrokes to return base.ProcessCmdKey(ref msg, keyData); which will give normal functionality to the keystroke without any overridden checks or whatever you may want to do with the captured keystrokes.

Need something like Accept Button in User Control

I need to have a Button on a UserControl (not Form) in a windows application to respond to "Enter" hit, the way a button which is set as the Accept Button of a Form works.
I cannot make the button to be focused, since I need other controls to be focused with tab change.
Any help is really appreciated :)
The AcceptButton is a property of Form and cannot be used for the UserControl. You can simply override ProcessCmdKey though and this will work so long as the user control has focus. Otherwise you will need to use the AcceptButton of the form separately or override the ProcessCmdKey in the form if you have multiple controls which could be active.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
button.PerformClick();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
If you set the Modifier property on the button to "Public", you can use the button as AcceptButton on the form. Unfortunately you cannot do it design-time with the properties window of Visual Studio, but you can do it in code.
public Form1()
{
InitializeComponent();
this.AcceptButton = userControl11.button1;
}
I know it's an old question, and already answered, however I use this in some situations:
private void UserControl11_Load(object sender, EventArgs e)
{
this.FindForm().AcceptButton = Button1;
}

how to link/set the ENTER to a function in winforms without relation to a Textbox control?

I'm using Winforms.
I've a screen approx. 10 fields. and a Update button.
But I don't want to use neither show on screen a button (btnUpdate).
I just want to show the the fields, they can change some values and by pressing the enter it should execute a function in code behind.
I googled and find some solutions like KeyPress on TextBox or whatever, but I don't want to link this to a TextBox. Then I found form.Acceptbutton = btnUpdate... but then I have to use a button on my designer.
so how can I make a situtation by not USING a Button control to do an update (in other words executing function in code-behind by pressing the Enter Key).
Try overriding the ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Return)
{
//Raise Update Event
return true;
}
else if (keyData == Keys.Escape)
{
//Raise Cancel Event
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}

How to prevent users from copying text from RichTextBox in a C# application?

Is it somehow possible to prevent end users from copying text from RichTextBox in a C# application? Maybe something like adding a transparent panel above the RichTextBox?
http://www.daniweb.com/software-development/csharp/threads/345506
Re: Disable copy and paste control for Richtextbox control Two steps
to be followed to disable the Copy-Paste feature in a textbox,
1) To stop right click copy/paste, disable the default menu and
associate the textbox with an empty context menu that has no menu
items.
2) To stop the shortcut keys you'll need to override the ProcessCmdKey
method:
C# Syntax (Toggle Plain Text)
private const Keys CopyKey = Keys.Control | Keys.C;
private const Keys PasteKey = Keys.Control | Keys.V;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if((keyData == CopyKey) || (keyData == PasteKey)){
return true;
} else {
return base.ProcessCmdKey(ref msg, keyData);
}
}
You need to subclass the rich edit box control, override the WM_COPY message, and do nothing when you receive it. (Do not delegate to DefWindowProc.)
You will also have to do the same for WM_CUT.
And still anyone will be able to get the text using some utility like Spy++.
One way to doing it is make access to clipbord object and than you can manitpulate content of clipbord.
method for clearing clipbord is : Clipboard.Clear Method
You could do this (I think):
//Stick this in the KeyDown event of your RichtextBox
if (e.Control && e.KeyCode == Keys.C) {
e.SuppressKeyPress = true;
}

Fire button click event using a key combination in c#

I've created custom button derived from a normal .Net button and have added the following property to add a short cut key combination:
public Keys ShortCutKey { get; set; }
I want this combination to fire the click event of the button but have no idea how to implement this when the button is placed on a form. I know the standard way of doing a button shortcut is to use the & before the short cut character but I need to use a key combination.
Any ideas?
Many Thanks
Override the form's ProcessCmdKey() method to detect shortcut keystrokes. Like this:
private bool findShortCut(Control.ControlCollection ctls, Keys keydata) {
foreach (Control ctl in ctls) {
var btn = ctl as MyButton;
if (btn != null && btn.ShortCutKey == keydata) {
btn.PerformClick();
return true;
}
if (findShortCut(ctl.Controls, keydata)) return true;
}
return false;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (findShortCut(this.Controls, keyData)) return true;
return base.ProcessCmdKey(ref msg, keyData);
}
Where MyButton is assumed to be your custom button control class.
I'm assuming you are using WinForms, given that the ampersand character is used in WinForms control captions to denote the shortcut character. If that is the case, then you can use the Button.PerformClick() method on a WinForms Button in order to fire the Click event manually.
If this is not the case and you are, in fact, using WPF; then take a look at the link Dmitry has posted in his comment for WPF Input Bindings.

Categories

Resources