Events And User Controls

Hi,

I've got a user control inheriting from System.Windows.Forms.TextBox and I've added a ListBox as a child.  I would like to expose an event when the ListBox changes visibility.  Any help would be greatly appreciated.

Code Snippet Follows====================================

public class TextBoxLookup : System.Windows.Forms.TextBox

{

private System.Windows.Forms.ListBox listBox1;

private void OpenListBox()

{

Control ctlParent = this.Parent;

ctlParent.Controls.Add(this.listBox1);

this.Text = "";

this.BackColor = Color.GhostWhite;

this.listBox1.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + 20);

this.listBox1.Width = this.Width;

this.listBox1.BringToFront();

this.listBox1.Visible = true;

}



Answer this question

Events And User Controls

  • Mattias Svensson

    Hi Rich.

    When cgraus says "expose your delegate", he means creating a public event on your class, which you raise in your event handler. This documentation should help: http://msdn.microsoft.com/library/default.asp url=/library/en-us/csref/html/vclrfEventPG.asp

    Hope this helps!

    Scott Nonnenberg



  • Vince15

    Your control should have an event handler that subscribes to the list boxes 'OnVisibleChanged', then expose a delegate that is called in this event handler.

  • JPlenert

    I've setup an event for the ListBox such as shown below but I'm vague on using a delegate to expose the event   Again any help woud be greatly appreciated.


    this
    .listBox1.VisibleChanged +=new EventHandler(listBox1_VisibleChanged);

    private void listBox1_VisibleChanged(object sender, EventArgs e)

    {

    }


  • Events And User Controls