User Control

K

Karuppasamy

Hi

I have created a User Control Containing a Panel and Rich Text Box. The
Panel
contains some other controls used for formatting the Text entered in the
Rich Text Box.

My Requirement is that The Panel has to be visible only when the User
Control got Focus and the Panel should not be shown to user when the User
Control lost its focus.

I have used the Following code, but its not working

this.GotFocus += new System.EventHandler(this.iCDCRichTextSection_GotFocus);

this.LostFocus += new System.EventHandler(this.iCDCRichTextSection_
LostFocus);


private void iCDCRichTextSection_ GotFocus (object sender, System.EventArgs
e)
{
this.IsControlPanelVisible = true;
}

private void iCDCRichTextSection_LostFocus (object sender, System.EventArgs
e)
{
this.IsControlPanelVisible = fasle;
}


why? What is the problem with this code?
Waiting for your reply.

Thanks and Regards
Karuppasamy Natarajan
 
G

Gabriele G. Ponti

Hello,

Your approach is correct, however since you didn't post the complete source
I can't tell you where the problem is.

I wrote a small sample to reproduce the wanted behavior, and it worked for
me. I created a user control with a panel (Visible set to False), and a Rich
Text Box. In the InitializeComponent() method of the user control I added
the event handlers for GotFocus and LostFocus:

this.richTextBox1.LostFocus += new
System.EventHandler(this.richTextBox1_LostFocus);
this.richTextBox1.GotFocus += new
System.EventHandler(this.richTextBox1_GotFocus);

And this is the implementation of the event handlers:

private void richTextBox1_GotFocus(object sender, System.EventArgs e)
{
this.panel1.Visible = true;
}

private void richTextBox1_LostFocus(object sender, System.EventArgs e)
{
this.panel1.Visible = false;
}

I noticed that in your sample code you use a property to show and hide the
panel. Your problem may be there.

HTH,

Gabriele
 
G

Gabriele G. Ponti

After further discussing the issue with Karuppasamy, I realized that to
achieve what he wanted he had to use the Enter() and Leave() events of the
UserControl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top