473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

switch between usercontrols

Hi everyone,

I have a windows forms application with several full screen Usercontrolls.
Now I would like to be able to switsch between them. So that when you click
a button UC1 will become invissible an UC2 will become vissible.

Doing this from my Form that contains the UCs works fine. I have a Sub that
makes all UC invissible and then the needed UC Vissible again. That way I
can call any usercontrol from my Form. But how can i do the same from one of
the UC? So that when you push a button on UC1, UC1 will become Invissible
and UC2 will become vissible?

If possible I would like to put most of the needed code in my Form, or even
better a sepperate class, so that I don't have to add a lot to everysingle
UC.

Thank you for any help

Johannes
Nov 20 '05 #1
3 1729
Cast the UserControl's Parent property to the type of form it's put on:

Inside the UserControl:

Public Sub DoSwitch()
If (Not Me.Parent Is Nothing) AndAlso (TypeOf Me.Parent Is
TheParentForm) Then
DirectCast(Me.Parent, TheParentForm).CallParentMethod
End If
End Sub

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Johannes Hammersen" <Jo****************@x75.net> wrote in message
news:#9**************@TK2MSFTNGP12.phx.gbl...
Hi everyone,

I have a windows forms application with several full screen Usercontrolls.
Now I would like to be able to switsch between them. So that when you click a button UC1 will become invissible an UC2 will become vissible.

Doing this from my Form that contains the UCs works fine. I have a Sub that makes all UC invissible and then the needed UC Vissible again. That way I
can call any usercontrol from my Form. But how can i do the same from one of the UC? So that when you push a button on UC1, UC1 will become Invissible
and UC2 will become vissible?

If possible I would like to put most of the needed code in my Form, or even better a sepperate class, so that I don't have to add a lot to everysingle
UC.

Thank you for any help

Johannes

Nov 20 '05 #2
> You might want to try raising an even, ...
...Now in your form that contains the user control, create a handler for the event.


First of all thank you for your help!

I have a lot of usercontrols with a quite a few buttons so using your way I
would have to bulid a lot of eventhandler. Even if I would combine a lot of
them, I'd still would have to add the Event to the Handles list for every
button in every UC. That would make one long confusing list.

Johannes
Nov 20 '05 #3
Hi Jay,
Now the question becomes, does a single button on each UC take you to the
next UC? (like Prev & Next in a Wizard).
Or does each UC have a button for every other UC? (I have 15 UC, so I have
15 buttons). Kind of like that.
Every UC has a few butons to a few other UCs which have buttons to other
UCs.
So at the end you will have to "navigate" through a few UCs to get to a
certian one.
But on the other hand every UC will have a button to take you back to the
first UC after executing some code.

.... Protected Sub ShowUC(uc As UCBase)
' hide previous uc
' show new uc
End Sub

....

I think I understood your sample. So I'll try to build it into my project.
But I don't see how I could change the UC.visible Property form UCBase,
doesn't that need to be done in the form?

I tried somesthing like this before:
Private _myBaseForm as Form1
_myBaseForm = Me.ParentForm
_myBaseForm.HideAllUserControls()
_myBaseForm.UserControls(2).Visible = True

Which semed to work, execpt that I had to remove the "as Form1" because I
kept getting an message box saying: "Cast not valid" when I tried to add the
uc to the form.
Why can't I dim _myBaseForm as Form1?

Thanks for your help
Johannes
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kate | last post by:
Hi: I have a picturebox control, and at runtime various usercontrols are added to it to make a diagram. As dynamically added usercontrols, they are of type VBExtender. Is there a way to save...
2
by: Emma | last post by:
Hi, I'm developing a GUI with almost all Usercontrols. It's been working wonderfull up till a few weeks ago, and really crashed yesterday. Suddenly I can no longer add some of my usercontrols...
4
by: Anders K. Jacobsen [DK] | last post by:
Hi I have some common UserControls i want to share between to sites (on the same mashine but on diffrent virtual paths). right now i have on solution file with aprox 10 projects. 2 of these is...
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
3
by: YYZ | last post by:
I swear I've done my research, and now I was just hoping someone could explain this to me. I've got a base class (usercontrol) that I am using just as an interface. Meaning, I've defined...
3
by: b747_440 | last post by:
Dear Newsgroup, I'm an old VB6.0 developper who switched some time ago to VB.NET 2005. I really like that new Visual Studio. However, something is going wrong now and I can't figure out, what it...
0
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: public delegate void SelectHandler(object sender,...
4
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.