Solved

event handling for composite controls

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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 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