Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm trying to create a custom messagebox.
But if one double click on the text (I'm using a label) the text of the label is copied to the clipboard.

I googled and found this:
private class SingleClickLabel : Label
    {
        protected override CreateParams CreateParams
        {
            get
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

                CreateParams cp = base.CreateParams;
                cp.ClassStyle &= ~0x0008;
                cp.ClassName = null;

                return cp;
            }
        }
    }

But I have no idea on how to use that class, and there fore I hope that some here can guide me to use it correct.

What I have tried:

googled to see how to use the code.
Posted
Updated 24-Feb-20 7:00am
Comments
Richard MacCutchan 25-Feb-20 6:11am    
Don't waste time copying code from Google, especially if you don't understand it. Take a step back and show us the code that you have written, and explain where the problem is.
Lupu5R3x 25-Feb-20 10:58am    
That's why I asked my question, to learn how to use the code, If I don't ask I don't learn, though most often I can find the answer to my questions using google, and that's the way I prefer to it, I hate to ask questions - course that means that I failed to find the answer on my own :(.

All I current have is a simple WinForm, that looks like a messagebox.
It's build over code examples found by googleing, I could had created it from scratch, but I saw no reason to recreate the wheel :).

My problem, is/was that that if I double clicked the label I use to display the message, the message is copied to the clipboard, and I wanted to prevent that.

/LR

1 solution

That class just creates a new control. Once you add that class to your project and compile it, the control will show up in the ToolBox when you go the designer for your form.
 
Share this answer
 
Comments
Lupu5R3x 24-Feb-20 15:19pm    
Sry, C# is new to me.
I don't understand, you answer :(.
I have added the class to my project form code (not design code).

/LR
Lupu5R3x 25-Feb-20 10:46am    
I figured it out, I just added the code to the design code, and changed my label to SingleClickLabel.

Though, I would had preferred to add it to the Toolbox, so I could use it in other projects without copying the code to the designer, but I guess I figure out how to that at some point in the future.

/LR
Dave Kreskowiak 25-Feb-20 11:10am    
You create a separate Control project to make a reusable control. Replace class that comes in the project with the class you have and compile it. That's pretty much it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900