Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Exposing UserControl Constituents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jokra - 12 Oct 2004 16:37 GMT
MAIN FORM: In my main form I have a treeview control docked on the left and a
panel control filling the rest of the form.
USER CONTROLS: I am constructing separate user controls to be displayed
within the content area of the form when a tree node is clicked. Each user
control has a panel control containing varius controls, ie textboxes, labels,
datagrid.

QUESTION: How can I expose the constituent controls on the user control so
that I can reference them from within my main form code?

Thanks.
Signature

Jokra the Barbarian

Imran Koradia - 12 Oct 2004 16:57 GMT
One way would be to change the access modifier for the controls to public (I
believe the detault is Friend (Internal) in VB and Private in C#). However,
that way, anyone using your user controls will be able to access all
properties of the constituent controls which may or may not be desirable.
You could only expose the properties that you would want to access (and
allow others to access) from the application using your user control.

for example, this one just returns the text of a textbox in your user
control.

ReadOnly Property TextBoxText() As String
   Get
       Return Me.TextBox1.Text
   End Get
End Property

hope that helps..
Imran.

> MAIN FORM: In my main form I have a treeview control docked on the left and a
> panel control filling the rest of the form.
[quoted text clipped - 7 lines]
>
> Thanks.
Jokra - 12 Oct 2004 17:31 GMT
I don't want to make each of the private controls public. Also, I think I
tried this and it didn't work. I found some posted code on another site, but
it's for VB, and haven't got it to work for C# yet:

Public Property Get Controls() as Object
    Set Controls = UserControl.Controls
End Property

I tried to port it to C#, but don't think I've got the syntax correct:
    public Object controls
        {
    set
     {
        controls = this.customPanel1.Controls;
     }
    get
                 {
        return(controls);
     }
         }

Thanks for your assistance!  -Jokra

> One way would be to change the access modifier for the controls to public (I
> believe the detault is Friend (Internal) in VB and Private in C#). However,
[quoted text clipped - 28 lines]
> >
> > Thanks.
Imran Koradia - 12 Oct 2004 18:17 GMT
> I don't want to make each of the private controls public. Also, I think I
> tried this and it didn't work. I found some posted code on another site, but
[quoted text clipped - 16 lines]
>   }
>           }

I assume you only want to be able to get the controls collection rather than
set it, right? In that case, here's the syntax:

public Object Controls
{
   get
   {
       return(this.customPanel1.Controls);
   }
}

hope that helps..
Imran.
Jokra - 12 Oct 2004 19:27 GMT
Imran-

Thank you so much. I ended up doing exactly what you first suggested,
setting the constituent controls modifier property to Public, then set the
usercontrol modifier property to Public within the main form.

Thanks for your help!

-Jokra

> > I don't want to make each of the private controls public. Also, I think I
> > tried this and it didn't work. I found some posted code on another site,
[quoted text clipped - 31 lines]
> hope that helps..
> Imran.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.