Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# object Problem Pin
kornkimhour24-Nov-11 19:41
kornkimhour24-Nov-11 19:41 
GeneralRe: C# object Problem Pin
Richard MacCutchan24-Nov-11 21:45
mveRichard MacCutchan24-Nov-11 21:45 
GeneralRe: C# object Problem Pin
BobJanova25-Nov-11 3:23
BobJanova25-Nov-11 3:23 
GeneralRe: C# object Problem Pin
kornkimhour25-Nov-11 3:34
kornkimhour25-Nov-11 3:34 
GeneralRe: C# object Problem Pin
kornkimhour24-Nov-11 21:58
kornkimhour24-Nov-11 21:58 
GeneralRe: C# object Problem Pin
kornkimhour24-Nov-11 22:18
kornkimhour24-Nov-11 22:18 
QuestionC# UserControl Focus Pin
ZawMinTun24-Nov-11 14:44
ZawMinTun24-Nov-11 14:44 
AnswerRe: C# UserControl Focus Pin
BillWoodruff24-Nov-11 18:13
professionalBillWoodruff24-Nov-11 18:13 
Assuming this is WinForms, and that you create multiple UserControls of the same Type at run-time:

1. obviously, if UserControl1 is completely covered (behind) UserControl2, or a bunch of other UserControls, you have no opportunity to click on anything in UserControl1: if that case ever exists: then you might want to do something like make a context-click (right-click for most folks) on any of your UserControls to send them to the back ? Or have a menu-item in the Main Form menu, or a context menu on every UserControl, that lets you select any one of the available UserControls, which it will then bring to the front ?

2. so, let's assume your UserControl1 is partially covered: let's assume there's going to be some area of UserControl1 visible and click-able: then assign a Click EventHandler in the UserControl definition code that brings it to the front; or if it already has a Click EventHandler, add a this.BringToFront(); line to it.

3. if we assume it could be partially covered, but what's visible is only TextBoxes, or some other object that completely fills the UserControl: then you don't have much choice but to enumerate all the Controls in the UserControl that could cause this condition, and assign a Click EventHandler that moves them to the front, or modify their existing MouseDown or Click EventHandlers as suggested in #2 above.

Do keep in mind that delegates/events are "multi-cast" and can have more than one EventHandler assigned to their "Invocation Lists." So if you had a "Click" handler for some object that you did not want to (or could not ?) modify, you can add an extra Click EventHandler to that object (assuming the entire object is not somehow "sealed," "locked," whatever). So this is quite legal:
C#
// at some point in your initialization code:
panel1.Click += new EventHandler(panel1_Click1);
panel1.Click += new EventHandler(panel1_Click2);
//
private void panel1_Click1(object sender, EventArgs e)
{
    Console.WriteLine("hello");
}

private void panel1_Click2(object sender, EventArgs e)
{
    Console.WriteLine("goodbye");
}
Discussion:

Both those Click EventHandlers will be executed on a Click on the UserControl.

If you are using C# 2.0 or later, you can add the EventHandler directly without using 'new EventHandler' syntax:
panel1.Click += panel1_Click1;
panel1.Click += panel1_Click2;
However, most folks like the auto-completion feature of Visual Studio that will generate the EventHandler stub for you ... so ... up to you.

Aside: my understanding is that in XAML (which I do not use) you cannot subscribe more than one EventHandler to an Event.

best, Bill
"... Sturgeon's revelation. It came to him that Science Fiction is indeed ninety-percent crud, but that also—Eureka!—ninety-percent of everything is crud. All things—cars, books, cheeses, hairstyles, people and pins are, to the expert and discerning eye, crud, except for the acceptable tithe which we each happen to like." early 1950's quote from Venture Sci-Fi Magazine on the origin of Sturgeon's Law, by author Theodore Sturgeon: source Oxford English Dictionary on-line "Word-of-the-Day."


modified 25-Nov-11 0:37am.

GeneralRe: C# UserControl Focus Pin
ZawMinTun24-Nov-11 19:05
ZawMinTun24-Nov-11 19:05 
QuestionPOP-UP CAPSLOCK Tray Application using C# Pin
jtstanish24-Nov-11 12:32
jtstanish24-Nov-11 12:32 
AnswerRe: POP-UP CAPSLOCK Tray Application using C# Pin
Luc Pattyn24-Nov-11 16:45
sitebuilderLuc Pattyn24-Nov-11 16:45 
GeneralRe: POP-UP CAPSLOCK Tray Application using C# Pin
jtstanish25-Nov-11 2:07
jtstanish25-Nov-11 2:07 
QuestionMouse not responding Pin
Joseph A Delinski Jr24-Nov-11 6:08
Joseph A Delinski Jr24-Nov-11 6:08 
AnswerRe: Mouse not responding Pin
Richard Andrew x6424-Nov-11 10:05
professionalRichard Andrew x6424-Nov-11 10:05 
GeneralRe: Mouse not responding Pin
Joseph A Delinski Jr24-Nov-11 10:10
Joseph A Delinski Jr24-Nov-11 10:10 
GeneralRe: Mouse not responding Pin
Joseph A Delinski Jr24-Nov-11 10:19
Joseph A Delinski Jr24-Nov-11 10:19 
GeneralRe: Mouse not responding Pin
Joseph A Delinski Jr24-Nov-11 10:26
Joseph A Delinski Jr24-Nov-11 10:26 
GeneralRe: Mouse not responding Pin
Richard Andrew x6424-Nov-11 10:32
professionalRichard Andrew x6424-Nov-11 10:32 
GeneralMessage Removed Pin
24-Nov-11 10:46
Joseph A Delinski Jr24-Nov-11 10:46 
GeneralRe: Mouse not responding Pin
Joseph A Delinski Jr24-Nov-11 11:20
Joseph A Delinski Jr24-Nov-11 11:20 
AnswerRe: Mouse not responding Pin
BillWoodruff24-Nov-11 18:42
professionalBillWoodruff24-Nov-11 18:42 
GeneralRe: Mouse not responding Pin
Joseph A Delinski Jr24-Nov-11 20:38
Joseph A Delinski Jr24-Nov-11 20:38 
QuestionUse single bool and bit flags for other bools. Pin
V K 224-Nov-11 1:39
V K 224-Nov-11 1:39 
AnswerRe: Use single bool and bit flags for other bools. PinPopular
Pete O'Hanlon24-Nov-11 2:27
mvePete O'Hanlon24-Nov-11 2:27 
GeneralRe: Use single bool and bit flags for other bools. Pin
harold aptroot24-Nov-11 3:07
harold aptroot24-Nov-11 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.