By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

User Control

P: n/a
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_GotFo cus);

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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Karuppasamy" <Ka*******************@isoftplc.com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
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_GotFo cus);
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

Jul 19 '05 #2

P: n/a
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.

"Gabriele G. Ponti" <gg*****@hotmail.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
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
"Karuppasamy" <Ka*******************@isoftplc.com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
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_GotFo cus);

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


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.