Solved

event handling for composite controls

Posted on 2012-03-22
4
203 Views
Last Modified: 2012-04-09
Hi Experts,

I am trying to build a windows form composite control. As of now the composite control only has one text box. In the contianing client (another windows form) I would like to be able to access the value entered in the textbox.

Should I create a event to be triggered when focus leaves the composite control (the text box for now). How do I do that?

Is there any other way to deal with this?

thanks in advance
0
Comment
Question by:olmuser
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37755086
You either directly publicly expose the TextBox (not recommended), or create a Public property to access the Text() property of the TextBox contained within.  So you just basically "wrap" the Text() property of the TextBox in your own Property at the UserControl level.
0
 
LVL 1

Author Comment

by:olmuser
ID: 37759016
Hi @idle_mind, thanks. I am sorryif I was not clear, but I am able to access the text box value as a public property of the composite control, but my current challenge is this. If it were a regular text box I would use the leave event of the control to check if the value has changed or not and update the underlying business model. Here I need a event to do the same. This is thinking along the lines of what I currently have. What other option is there with a composite control? thanks
0
 
LVL 1

Author Comment

by:olmuser
ID: 37759065
Come to think of it, I could use some events like, when the form is closed or when the save button is clicked, for now, but I would like to understand how events are done in composite controls, thanks
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37759318
Not sure what you're after here...

This is an example of raising a custom "leave" event for the UserControl when the TextBox's Leave() event fires:
    public partial class UserControl1 : UserControl
    {

        public delegate void TextBoxLeaveDelegate(Object sender);
        public event TextBoxLeaveDelegate TextBoxLeave;

        public string TextBoxValue
        {
            get { return textBox1.Text; }
        }

        public UserControl1()
        {
            InitializeComponent();
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            if (TextBoxLeave != null)
            {
                TextBoxLeave(this);
            }
        }

    }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now