Determine number of tabs in Tabcontrol in 'If' statement

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 1057 Views - Last Post: 24 February 2012 - 12:54 PM Rate Topic: -----

#16 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 19 February 2012 - 11:14 AM

View Postcurlyfries1999, on 19 February 2012 - 11:18 PM, said:

I have found the problem. I put it in a timer sub but forgot to start it. Stupid or what?!

I dont think if that is the correct sub to put it, because it is the misuse of resources. You dont need in every few seconds to check how many tabs you have, you only need to check that at the time you close a tab.
Was This Post Helpful? 1
  • +
  • -

#17 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 09:04 AM

What else do you suggest? I am new to VB and programing all together so i don't know much about it.
Was This Post Helpful? 0
  • +
  • -

#18 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 09:25 AM

View Postcurlyfries1999, on 23 February 2012 - 09:49 PM, said:

What else do you suggest? I am new to VB and programing all together so i don't know much about it.

Probably you dont need a timer here, as I and Ryano121 have said, it is a waste of resources to have a timer that checks in every milliseconds how many tabs remains.
What you can do is to put the code in the sub that closes those tabs, and every time user tries to close a tab, then just check how many tabs remains, if it is the only tab, then close the application.
Was This Post Helpful? 0
  • +
  • -

#19 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 11:59 AM

View Postsmohd, on 23 February 2012 - 09:25 AM, said:

View Postcurlyfries1999, on 23 February 2012 - 09:49 PM, said:

What else do you suggest? I am new to VB and programing all together so i don't know much about it.

Probably you dont need a timer here, as I and Ryano121 have said, it is a waste of resources to have a timer that checks in every milliseconds how many tabs remains.
What you can do is to put the code in the sub that closes those tabs, and every time user tries to close a tab, then just check how many tabs remains, if it is the only tab, then close the application.

Yeah, i knew that. Do you know what sub i could use. I had a look but i coulldn't find one that seemed to match.
Was This Post Helpful? 0
  • +
  • -

#20 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1051
  • View blog
  • Posts: 2,231
  • Joined: 30-January 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:10 PM

How does the user close a tab?
Was This Post Helpful? 0
  • +
  • -

#21 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,434
  • Joined: 25-September 09

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:22 PM

In the tabcontrol object is an event called ControlRemoved. Since the tabpage is control, that event should be fired everytime a control is removed. You would just check the count there and react. Keep in mind that while closing the last tab this event is checked so you will probably have a tabcount of 1 during the check. So if TabControl1.TabCount = 0 won't work.
Was This Post Helpful? 0
  • +
  • -

#22 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:27 PM

What code/event do you use to close those tabs now? Have a button or what? That is where you are going to put the check for the last tab.
May be if we can see the code we may have better replies..
Was This Post Helpful? 0
  • +
  • -

#23 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:33 PM

View PostRyano121, on 23 February 2012 - 12:10 PM, said:

How does the user close a tab?

CTRL+w but there can be more than one tab open at a time.
Was This Post Helpful? 0
  • +
  • -

#24 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:39 PM

View Postsmohd, on 23 February 2012 - 12:27 PM, said:

What code/event do you use to close those tabs now? Have a button or what? That is where you are going to put the check for the last tab.
May be if we can see the code we may have better replies..

I have a toolstrip menu item for removing a tab. It has a shortcut key of ctrl+w. the code is:
Private Sub RemoveXTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveXTabToolStripMenuItem.Click
        Form1.TabControl1.SelectedTab.Dispose()
    End Sub

Was This Post Helpful? 0
  • +
  • -

#25 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,434
  • Joined: 25-September 09

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:41 PM

But what smohd and others are asking is:
You have code that detects when Ctrl-W is pressed and at that point you close a tab.
Why not just check at that point if you have just closed the last tab?
Was This Post Helpful? 0
  • +
  • -

#26 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,434
  • Joined: 25-September 09

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:46 PM

OK so why not check to see if you have 0 tabs after you dispose and close?
Was This Post Helpful? 0
  • +
  • -

#27 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:49 PM

View PostCharlieMay, on 23 February 2012 - 12:41 PM, said:

But what smohd and others are asking is:
You have code that detects when Ctrl-W is pressed and at that point you close a tab.
Why not just check at that point if you have just closed the last tab?

I tryed that and it didn't work. I used:
If e.KeyCode = Keys.Control & Keys.W Then
            If My.Forms.Form1.TabControl1.TabCount = 0 Then
                Application.Exit()
            End If
        End If

Was This Post Helpful? 0
  • +
  • -

#28 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 12:54 PM

Then there is the place to put a check, something like:
        If TabControl1.TabCount = 1 Then 'check if there is only one remaining tab
            Application.Exit()
        End If
        TabControl1.SelectedTab.Dispose()


Then there is the place to put a check, something like:
        If TabControl1.TabCount = 1 Then 'check if there is only one remaining tab
            Application.Exit()
        End If
        TabControl1.SelectedTab.Dispose()

Was This Post Helpful? 0
  • +
  • -

#29 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 01:03 PM

That didn't work either. I don't want the program to close when there is one tab. I want it to close when there are zero.

View PostCharlieMay, on 23 February 2012 - 12:46 PM, said:

OK so why not check to see if you have 0 tabs after you dispose and close?

That still wont work!
Was This Post Helpful? 0
  • +
  • -

#30 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Determine number of tabs in Tabcontrol in 'If' statement

Posted 23 February 2012 - 01:06 PM

View Postcurlyfries1999, on 24 February 2012 - 01:43 AM, said:

That didn't work either.

How you tried it? Better show us how you updated your sub, just put the code I posted in RemoveXTabToolStripMenuItem_Click() sub, no need to check for the key because the sub is raised when user press those keys(that is what shortcut setting does)

View Postcurlyfries1999, on 24 February 2012 - 01:43 AM, said:

I don't want the program to close when there is one tab. I want it to close when there are zero.

But you want it to close if user try to close the last tab, so probably you have to check is if it only remains one. Because if there is no tab, then no one will try to close a tab and so the event wont raise!!

This post has been edited by smohd: 23 February 2012 - 01:11 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3