Solved

event handling for composite controls

Posted on 2012-03-22
4
206 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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