My goal is: when I click mouse on some control and hold CTRL button I'll get form that gives me possibility to change user right to this control. On a single button it looks like:
if (Control.ModifierKeys == Keys.Control && Keys.Control == Keys.Control)
{
frmUsersGroups frmUsersGroups = new frmUsersGroups(this.Name, sender.ToString());
frmUsersGroups.ShowDialog();
}
else
{//open some form}
Bu I don't want to place this code on every control click event. Is there any possibility to do that globaly in whole application ? I'd like to click on some control, recognise it's type, name, parent form, etc...
regards

JureRank #2,128 · 670 reputationPosted Oct 19, 2010, 7:27 AM EDT
For example, you'd create a class called "MyButton" which inherits System.Windows.Forms.Button, then you'd create a static event, and last, you'd need to override OnClick, so that it calls your event. Now you just need to set the event once for all buttons, once for all textboxes...
BUT, if you'll be setting event only once (won't add/remove functions from it later), then you can skip the whole static event deal, write a function instead (inside your inheriting control) and call it in overridden OnClick.
Sam HobbsRank #107 · 20.5K reputationPosted Oct 19, 2010, 1:12 PM EDT
There have been similar questions in these forums with answers a few months ago.