Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

event handling for composite controls

Posted on 2012-03-22
4
Medium Priority
?
209 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:Mydeen Yussouf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

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:Mydeen Yussouf
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:Mydeen Yussouf
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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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