Solved

event handling for composite controls

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

22 Experts available now in Live!

Get 1:1 Help Now