Click here to Skip to main content
15,915,163 members
Home / Discussions / C#
   

C#

 
QuestionTips for creating a custom message inbox Pin
mihansen1-Dec-05 7:45
mihansen1-Dec-05 7:45 
QuestionSleep or Wait functions in ASP.NET Pin
TheMajorRager1-Dec-05 7:02
TheMajorRager1-Dec-05 7:02 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Jared Parsons1-Dec-05 7:46
Jared Parsons1-Dec-05 7:46 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Colin Angus Mackay1-Dec-05 8:28
Colin Angus Mackay1-Dec-05 8:28 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Dave Kreskowiak1-Dec-05 10:54
mveDave Kreskowiak1-Dec-05 10:54 
AnswerRe: Sleep or Wait functions in ASP.NET Pin
Reanalyse1-Dec-05 11:43
Reanalyse1-Dec-05 11:43 
QuestionHow to add Event and Delegates to UserControls? Pin
2hdass1-Dec-05 6:41
2hdass1-Dec-05 6:41 
AnswerRe: How to add Event and Delegates to UserControls? Pin
Sean Michael Murphy2-Dec-05 9:41
Sean Michael Murphy2-Dec-05 9:41 
2hdass wrote:
I want this control to act exactly like a normal listbox. I need the ChangedSelectedIndex event on it so that when i click on it in the main program it will do something. Oh, and also i want the button to work too, -- to have a MouseClick event.


You have to bubble the events up. In the user control, wire up the SelectedIndexChanged event of your ListBox and the Click event of the Button to local event handlers like this:
C#
namespace Test {
   public class UserControl1 : System.Windows.Forms.UserControl {
      // Add this to bubble up the listbox event.
      public event EventHandler SelectedIndexChanged;
   
      // Have to rename this event, since "Click" would hide the user
      // control Click event.
      public event EventHandler ButtonClick;
   
      private System.Windows.Forms.ListBox listBox1;
      private System.Windows.Forms.Button button1;
   
      // Windows InitializeComponent() code skipped
   
      public UserControl1() {
         InitializeComponent();
   
         // Wire up the local control events.
         this.listBox1.SelectedIndexChanged += 
                  new System.EventHandler(this.listBox1_SelectedIndexChanged);
         this.button1.Click += new System.EventHandler(this.button1_Click);
      }
   
      private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) {
         // Raise the event to listeners of your user control 
         if (this.SelectedIndexChanged != null) // Check for subscribers
            this.SelectedIndexChanged(this, e);
      }
   
      private void button1_Click(object sender, System.EventArgs e) {
         // Raise the event to listeners of your user control 
         if (this.ButtonClick != null) // Check for subscribers
            this.ButtonClick(this, e);
      }
   }
}
   
Now the consumers of your control can wire up the new user control events you've exposed, SelectedIndexChanged and ButtonClick, and receive notification of events to the controls that make up your user control.

Share and enjoy.
Sean
QuestionExtracting keys and values from SortedList Pin
smurfy341-Dec-05 5:47
smurfy341-Dec-05 5:47 
AnswerRe: Extracting keys and values from SortedList Pin
Alessandro Febretti1-Dec-05 10:43
Alessandro Febretti1-Dec-05 10:43 
GeneralRe: Extracting keys and values from SortedList Pin
smurfy342-Dec-05 3:01
smurfy342-Dec-05 3:01 
QuestionHow do I create a Custom DashStyle?? Pin
...---...1-Dec-05 5:03
...---...1-Dec-05 5:03 
Questiondefault email client Pin
ppp0011-Dec-05 4:47
ppp0011-Dec-05 4:47 
AnswerRe: default email client Pin
Curtis Schlak.1-Dec-05 14:47
Curtis Schlak.1-Dec-05 14:47 
QuestionGroups in Active Directory Pin
zaboboa1-Dec-05 4:06
zaboboa1-Dec-05 4:06 
AnswerRe: Groups in Active Directory Pin
Jared Parsons1-Dec-05 7:53
Jared Parsons1-Dec-05 7:53 
QuestionMultithreading Question Pin
akyriako781-Dec-05 2:09
akyriako781-Dec-05 2:09 
AnswerRe: Multithreading Question Pin
S. Senthil Kumar1-Dec-05 3:37
S. Senthil Kumar1-Dec-05 3:37 
GeneralRe: Multithreading Question Pin
akyriako781-Dec-05 6:13
akyriako781-Dec-05 6:13 
GeneralRe: Multithreading Question Pin
Jared Parsons1-Dec-05 7:55
Jared Parsons1-Dec-05 7:55 
QuestionHow to access a configuration file in a COM add-in Pin
cathignol1-Dec-05 1:36
cathignol1-Dec-05 1:36 
QuestionHow to copy file from a server to the other when other server is in different domain!!!! Pin
sammi19761-Dec-05 1:33
sammi19761-Dec-05 1:33 
AnswerRe: How to copy file from a server to the other when other server is in different domain!!!! Pin
Colin Angus Mackay1-Dec-05 4:19
Colin Angus Mackay1-Dec-05 4:19 
Questiondouble buffering Pin
bwagz1-Dec-05 1:32
bwagz1-Dec-05 1:32 
AnswerRe: double buffering Pin
mcljava2-Dec-05 8:26
mcljava2-Dec-05 8:26 

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.