# Change view

**URL:** https://tech-community.robotics.abb.com/t/change-view/2237
**Category:** Developer Tools
**Created:** [October 22, 2008, 3:55pm UTC](https://tech-community.robotics.abb.com/t/change-view/2237 "2008-10-22T15:55:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![suntzu999](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@suntzu999](https://tech-community.robotics.abb.com/u/suntzu999)
#### Post date: [October 22, 2008, 3:55pm UTC](https://tech-community.robotics.abb.com/t/change-view/2237/1 "2008-10-22T15:55:41Z")

</div>

Hello all!!!

I’m just newbies in RAB 👍 , and I want to know how to change the form when one button is pushed. (the same of a touch pannel for change the view…)

Thx

---

<div class="post-metadata">

### Author: ![Ingela](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@Ingela](https://tech-community.robotics.abb.com/u/Ingela)
#### Post date: [October 22, 2008, 4:31pm UTC](https://tech-community.robotics.abb.com/t/change-view/2237/2 "2008-10-22T16:31:32Z")

</div>

Hello!

If the second form (that you want to launch when pressing a btn) inherits TpsForm the code to achieve this is very simple:

private void button1\_Click(object sender, EventArgs e)

{  
\_viewProd = new ViewProd();

\_viewProd.ShowMe(this);

}

If the second view inherits TpsControl, however, you need to add it to the control collection of the first form before you launch it (just like an ordinary .Net control).

---

<div class="post-metadata">

### Author: ![suntzu999](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@suntzu999](https://tech-community.robotics.abb.com/u/suntzu999)
#### Post date: [October 23, 2008, 8:10am UTC](https://tech-community.robotics.abb.com/t/change-view/2237/3 "2008-10-23T08:10:02Z")

</div>

Hello…

Thank you for your help,

I have try to do the same in VB with the following lines :

Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
Dim \_view2 As view2  
Me.Hide()  
\_view2 = New view2()  
\_view2.Show()  
\_view2 = Nothing  
End Sub

I have created the Form view2

but when i execute the code in the virtualflex, the form1 is good hiding but the view2 is not show.

do you have a solution for that?

thx

---

<div class="post-metadata">

### Author: ![Ingela](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@Ingela](https://tech-community.robotics.abb.com/u/Ingela)
#### Post date: [October 23, 2008, 11:21am UTC](https://tech-community.robotics.abb.com/t/change-view/2237/4 "2008-10-23T11:21:11Z")

</div>

If your second view is a TpsForm, this is an example of how to do it:

Private Sub button1\_Click(ByVal sender As Object, ByVal e As EventArgs)  
Try  
Me.\_viewProduction = New ViewProduction(Me.\_controller)  
AddHandler Me.\_viewProduction.Closed, New EventHandler(AddressOf Me.\_viewClosed)  
Me.\_viewProduction.ShowMe(Me)  
Me.\_viewProduction.Activate  
Catch exception As Exception  
Me.DisplayErrorMessage(exception.Message)  
End Try  
End Sub

Some advice:

1. Use try - catch for ALL event handlers. There is only ONE GUI thread on the FlexPendant, if you break it the FlexPendant will crash…
2. To save resources on the FlexPendant, use only ONE Controller object in your application, and pass it as an argument to the secondary view.
3. Add event handler to be notified when the second view is closed. In this event handler you call the Dispose method of the second view and set it to Nothing. Make sure the Dispose method of the second view cleans up properly (eg. objects that are holding subscriptions to controller events should release these before they are disposed of), but don’t kill the Controller object that was passed to it!
4. Launch the second view.
5. Call a method in the second view that activates any subscriptions to controller events and updates the UI.

Also - I really recommend you to spend some time reading all relevant sections in the User’s Guide. There is quite a lot to think about when you are coding an application for a small device with limited resources, such as the FlexPendant.
