User Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karuppasamy

    #1

    User Control

    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.EventHan dler(this.iCDCR ichTextSection_ GotFocus);

    this.LostFocus += new System.EventHan dler(this.iCDCR ichTextSection_
    LostFocus);


    private void iCDCRichTextSec tion_ GotFocus (object sender, System.EventArg s
    e)
    {
    this.IsControlP anelVisible = true;
    }

    private void iCDCRichTextSec tion_LostFocus (object sender, System.EventArg s
    e)
    {
    this.IsControlP anelVisible = fasle;
    }


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

    Thanks and Regards
    Karuppasamy Natarajan


  • Gabriele G. Ponti

    #2
    Re: User Control

    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 InitializeCompo nent() method of the user control I added
    the event handlers for GotFocus and LostFocus:

    this.richTextBo x1.LostFocus += new
    System.EventHan dler(this.richT extBox1_LostFoc us);
    this.richTextBo x1.GotFocus += new
    System.EventHan dler(this.richT extBox1_GotFocu s);

    And this is the implementation of the event handlers:

    private void richTextBox1_Go tFocus(object sender, System.EventArg s e)
    {
    this.panel1.Vis ible = true;
    }

    private void richTextBox1_Lo stFocus(object sender, System.EventArg s e)
    {
    this.panel1.Vis ible = 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


    "Karuppasam y" <Karuppasamy.Na tarajan@isoftpl c.com> wrote in message
    news:OWE5zDEcDH A.1204@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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[/color]
    System.EventHan dler(this.iCDCR ichTextSection_ GotFocus);[color=blue]
    >
    > this.LostFocus += new System.EventHan dler(this.iCDCR ichTextSection_
    > LostFocus);
    >
    >
    > private void iCDCRichTextSec tion_ GotFocus (object sender,[/color]
    System.EventArg s[color=blue]
    > e)
    > {
    > this.IsControlP anelVisible = true;
    > }
    >
    > private void iCDCRichTextSec tion_LostFocus (object sender,[/color]
    System.EventArg s[color=blue]
    > e)
    > {
    > this.IsControlP anelVisible = fasle;
    > }
    >
    >
    > why? What is the problem with this code?
    > Waiting for your reply.
    >
    > Thanks and Regards
    > Karuppasamy Natarajan
    >
    >[/color]


    Comment

    • Gabriele G. Ponti

      #3
      Re: User Control

      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" <ggponti@hotmai l.com> wrote in message
      news:uKgT$MVcDH A.3248@tk2msftn gp13.phx.gbl...[color=blue]
      > Hello,
      >
      > Your approach is correct, however since you didn't post the complete[/color]
      source[color=blue]
      > 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[/color]
      Rich[color=blue]
      > Text Box. In the InitializeCompo nent() method of the user control I added
      > the event handlers for GotFocus and LostFocus:
      >
      > this.richTextBo x1.LostFocus += new
      > System.EventHan dler(this.richT extBox1_LostFoc us);
      > this.richTextBo x1.GotFocus += new
      > System.EventHan dler(this.richT extBox1_GotFocu s);
      >
      > And this is the implementation of the event handlers:
      >
      > private void richTextBox1_Go tFocus(object sender, System.EventArg s e)
      > {
      > this.panel1.Vis ible = true;
      > }
      >
      > private void richTextBox1_Lo stFocus(object sender, System.EventArg s e)
      > {
      > this.panel1.Vis ible = 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
      >
      >
      > "Karuppasam y" <Karuppasamy.Na tarajan@isoftpl c.com> wrote in message
      > news:OWE5zDEcDH A.1204@TK2MSFTN GP12.phx.gbl...[color=green]
      > > 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[/color][/color]
      User[color=blue][color=green]
      > > Control lost its focus.
      > >
      > > I have used the Following code, but its not working
      > >
      > > this.GotFocus += new[/color]
      > System.EventHan dler(this.iCDCR ichTextSection_ GotFocus);[color=green]
      > >
      > > this.LostFocus += new System.EventHan dler(this.iCDCR ichTextSection_
      > > LostFocus);
      > >
      > >
      > > private void iCDCRichTextSec tion_ GotFocus (object sender,[/color]
      > System.EventArg s[color=green]
      > > e)
      > > {
      > > this.IsControlP anelVisible = true;
      > > }
      > >
      > > private void iCDCRichTextSec tion_LostFocus (object sender,[/color]
      > System.EventArg s[color=green]
      > > e)
      > > {
      > > this.IsControlP anelVisible = fasle;
      > > }
      > >
      > >
      > > why? What is the problem with this code?
      > > Waiting for your reply.
      > >
      > > Thanks and Regards
      > > Karuppasamy Natarajan
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...