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 / Visual Studio.NET / IDE / September 2004

Tip: Looking for answers? Try searching our database.

UserControl / ActiveControl / Designer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jos? Araujo - 01 Sep 2004 14:47 GMT
Hi,

I am trying to develop a component that inherit from UserControl for my
application.

My goal with that component is not to reuse it in many places through the
project, but to instanciate it dynamically when i need to show it in a form.

What happens is that i have a relatively huge form (like 10 tabs) and in
run-time and design-time loading/using the form takes for ever.

I thought it would be nice to instanciate the content of the tab whenever
the user goes to it (because it can happen that i user never goes to a tab).

I was able to create my component based on UserControl; however, i need the
ActiveControl property of the component to still give the correct result.
For instance, if i have three textboxes in my component and i query the
ActiveControl of the form i need it to tell me which box has the focus (not
to tell me that my component has the focus).

I was looking how to solve the problem, and i noticed that the ActiveControl
property cannot be overriden in my component, so i changed my component to
inherit from Control, and that works... however, i lost VS IDE functionality
to modify the looks of my component!

My question (finally) is: what VS.NET IDE needs into a class to be able to
show it in the form designer mode???

Thanks a lot, Jos? Araujo.
Carlos J. Quintero [MVP] - 01 Sep 2004 15:48 GMT
Hola Jos?,

You should use the Usercontrol. Of course, the UserControl is a unit despite
its constituents and Form.ActiveControl returns the UserControl when it is
the active control. And of course you can not override the ActiveControl
property of the UserControl because it knows quite well which constituent
control is the active one, while you could cheat...

What you can do is to take into account if the active control of the form is
a UserControl and in that case to query the ActiveControl of the
UserControl. For example, put your usercontrol and a timer on a form and
paste this code:

   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

       If TypeOf Me.ActiveControl Is UserControl Then
           Me.Text = DirectCast(Me.ActiveControl,
UserControl).ActiveControl.Name
       Else
           Me.Text = Me.ActiveControl.Name
       End If

   End Sub

Signature

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)

> Hi,
> I was able to create my component based on UserControl; however, i need the
> ActiveControl property of the component to still give the correct result.
> For instance, if i have three textboxes in my component and i query the
> ActiveControl of the form i need it to tell me which box has the focus (not
> to tell me that my component has the focus).
Jos? Araujo - 01 Sep 2004 16:32 GMT
Thanks for your answer...

I think i will be forced to use the UserControl. However, in my case it
would be better to use Control class...

What happens is that I do need to know which is the actual activecontrol.
This user control that i am creating is not a real one, it is just a hack to
make my program easily to develop (since it is more granural, more people
can work on it at the same time), and faster to load (both at run-time and
design-time).

We have developed a set of "ScreenSystem" classes that lets us customize the
behavior/look of our forms on runtime, if the usercontrol that i am creating
does not return the correct ActiveControl that creates problem for me.

Another point is: it would be really nice to just know how VS.NET tells the
difference between something that should show the Form designer and
somethign that should show the Component Designer. I was reading about it
and I do NOT find classes that are document in the help files like:
 System.Windows.Forms.Design.ControlDesigner, which i think is the one that
i need to use (or a child of it).

Anyways, i think i am going to use the tweak you propouse... Thanks for your
help... Jos?.

> Hola Jos?,
>
[quoted text clipped - 29 lines]
> (not
> > to tell me that my component has the focus).

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.