Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to ask that i have a windows form named Form_Save of which i want to create ProcessCmdKey(Link for Refrence of ProcessCMDKeys) in another class but it should read keys from "Form_Save" and want to use it in "Form_Save" as a method or function. Is This possible? if yes how?

Sorry if i was not clear enough


Thanks in advance
Posted
Comments
Thomas Daniels 17-Feb-15 5:34am    
What do you mean by "and want to use it in Form_Save as a method or function"?
agent_kruger 17-Feb-15 5:58am    
i meant that the function would be declared in different class and will be used in Form_Save.
Thomas Daniels 17-Feb-15 6:00am    
Why do you want to do that? Is it easier to just use ProcessCmdKeys in Form_Save itself, so why not use that?
agent_kruger 17-Feb-15 6:03am    
i want to use the same method in every form and so i wanted to declare it once and call it at form load.

1 solution

In your comment, you said that you want to do this so you can re-use the method in other forms. In that case, you can make a form that handles ProcessCmdKey, and make Form_Save (and perhaps other forms) derive from that form:
C#
class ProcessCmdKeysForm : Form
{
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        // ...
    }
}

class Form_Save : ProcessCmdKeysForm
{
    // ...
}

class AnotherFormIfYouWant : ProcessCmdKeysForm
{
    // ...
}
 
Share this answer
 
Comments
agent_kruger 17-Feb-15 6:19am    
looks good so far but how am i going to use "ProcessCmdKey" function then?
Thomas Daniels 17-Feb-15 6:21am    
You can change its content in the ProcessCmdKeysForm class.
agent_kruger 17-Feb-15 6:34am    
thanks man that answer really helped me
Thomas Daniels 17-Feb-15 6:45am    
You're welcome!

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