Link to home
Start Free TrialLog in
Avatar of Russ Suter
Russ Suter

asked on

Winforms TextBox - need custom balloon text on invalid operation

I am subclassing a TextBox so it will disallow cut, copy, and paste actions. I'd like it to show a customized message similar to the one seen when you attempt to copy text from a regular TextBox that has the PasswordChar property set.
User generated imageI've provided a sample of the overridden WndProc method which right now only sets a ToolTip. This is not what I want. I want a popup bubble like the picture (including icon, title, and message text) that will disappear after a few seconds.
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_COPY:
                    if (AllowClipboard)
                    {
                        base.WndProc(ref m);
                    }
                    else
                    {
                        _toolTip.SetToolTip(this, "Illegal Copy Operation. You will now be arrested!");
                    }
                    break;
                case WM_PASTE:
                    if (AllowClipboard)
                    {
                        base.WndProc(ref m);
                    }
                    else
                    {
                        _toolTip.SetToolTip(this, "Illegal Paste Operation. You will now be arrested!");
                    }
                    break;
                case WM_CUT:
                    if (AllowClipboard)
                    {
                        base.WndProc(ref m);
                    }
                    else
                    {
                        _toolTip.SetToolTip(this, "Illegal Cut Operation. You will now be arrested!");
                    }
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

Open in new window

Avatar of Arana (G.P.)
Arana (G.P.)

set the IsBaloon property of the tooltip to TRUE
Avatar of Russ Suter

ASKER

I've already tried that. It does not do what I described above. Also, it still behaves like a tooltip meaning it is only visible when the mouse hovers over the control. This is not at all the same behavior as when you attempt to copy text from a password field as I described above.
you can create the tooltip in your validation code and dispose it when user changes the text

ttnocopy = new ToolTip();
ttnocopy.IsBalloon = true;
ttnocopy.Show("Invalid Operation COPY", textbox1, 0);


then dispose it when user starts typing (maybe on LEAVE event so it doesnt popup when hovering)

ttnocopy.Dispose();
The ToolTip control does not work. I need a message that will appear when the user tries to cut/copy/paste using Ctrl+X/C/V and then disappear as in the example I mentioned above. The ToolTip only shows when the mouse hovers over the control. This is not the desired behavior.
that is why you specifically SHOW it with .show, then it will show whenever you call it, and thats why it needs to be disposed or disabled once you are finised showing it so it doesnt show on hover until you again validate the input
Then how do I get the icon and the title text to show as also shown in the original post?
ASKER CERTIFIED SOLUTION
Avatar of Arana (G.P.)
Arana (G.P.)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow, that's mostly there. The only thing now is that it is jumping around a bit based on current cursor position. Is there a way to fix it relative to the location of the textbox itself?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial