Solved

open form2, TabPage 10... winform VB.NET 2003

Posted on 2010-09-15
15
742 Views
Last Modified: 2012-05-10
Hi Experts,

I have 2 winforms
Form1 has 1 button... if clicked, it opens form2
Form2 has TabControl1 with xx tab pages...
I want Winform1 button to open winform2 and go direct to TabPage10.

Hope that makes sense?

Thanks,
Roberto
0
Comment
Question by:RobertoFreemano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
15 Comments
 

Author Comment

by:RobertoFreemano
ID: 33685045
I've tried:

Dim form2 as new Form
Form2.TabContol1...... get lost here

:(
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 50 total points
ID: 33685310
In form2 load set
 Me.TabControl1.SelectedTab = TabPage10
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685387
more specfic...

Private WithEvents f2 As Form
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        If f2 Is Nothing Then
            f2 = YourFormNAme
        End If
        If f2.WindowState = FormWindowState.Minimized Then
            f2.WindowState = FormWindowState.Normal
        End If

        f2.StartPosition = FormStartPosition.CenterScreen
        f2.ShowDialog()

           End Sub
 Private Sub f2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles f2.FormClosing
        f2 = Nothing
    End Sub

'In Form2 Load  event
Me.TabControl1.SelectedTab = TabPage10

Open in new window

0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

Author Comment

by:RobertoFreemano
ID: 33685449
Hi jtoutou,
I tried:
Form2.TabControl.SelectedTab = TabPage10

Error Message = "Name 'TabPage10' is not declared"
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685464
do you have tabpage10?
0
 

Author Comment

by:RobertoFreemano
ID: 33685465
Hi jtoutou,

Page didn't refresh in time :(

will try your code :)
0
 

Author Comment

by:RobertoFreemano
ID: 33685648
Couple of errors :(

f2 = Form2 .. Error = 'Form2 is a type and cannot be used as an expression'.

Me.TabControl1... error = 'TabConrtol1' is not a member of 'WindowsApplication.Form1'
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685681
Me.TabControl1.SelectedTab = TabPage10 You will put this code in the form load event (the form opened with the button click ...not the form1..The form that contains the tabcontrol)
in the button click event set:

 If f2 Is Nothing Then
            f2 = New Form2
        End If
        If f2.WindowState = FormWindowState.Minimized Then
            f2.WindowState = FormWindowState.Normal
        End If

        f2.StartPosition = FormStartPosition.CenterScreen
        f2.ShowDialog()
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 50 total points
ID: 33685699
Another example:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        Form2.Show()
    End Sub

End Class

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TabControl1.SelectedIndex = 9
    End Sub

End Class

Open in new window

0
 

Author Comment

by:RobertoFreemano
ID: 33685817
Sorry jtoutou,

I cannot follow instructions for toffee ;(

Form 1 - button1 click event =
If f2 Is Nothing Then
            f2 = YourFormNAme
        End If
        If f2.WindowState = FormWindowState.Minimized Then
            f2.WindowState = FormWindowState.Normal
        End If

        f2.StartPosition = FormStartPosition.CenterScreen
        f2.ShowDialog()

Form2 = Load event = Me.TabControl1.SelectedTab = TabPage10

I get an error on Form1 = [f2 = New Form2]
&
[  If f2.WindowState = FormWindowState.Minimized Then]
---error--------------------------------------
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an object
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685826
Try @idle's code is much more simple
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685867
Hope it Helps:)
'This is In Form1
 Private WithEvents f2 As Form
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        If f2 Is Nothing Then
            f2 = YourFormNAme
        End If
        If f2.WindowState = FormWindowState.Minimized Then
            f2.WindowState = FormWindowState.Normal
        End If

        f2.StartPosition = FormStartPosition.CenterScreen
        f2.ShowDialog()

           End Sub
 Private Sub f2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles f2.FormClosing
        f2 = Nothing
    End Sub






'This is In Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TabControl1.SelectedTab = TabPage10
End Sub

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685872
f2= new Form2
0
 

Author Closing Comment

by:RobertoFreemano
ID: 33685883
Either code showed errors, so I combined Idle_Minds code:
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        Form2.Show()
    End Sub

with jtoutou's code:
Me.TabControl1.SelectedTab = TabPage10

now it works ;)

Thanks Guys
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33685908
Glad i helped you Robberto!
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question