j.s.banger
j.s.banger

Reputation: 412

how can closed the TAB page by click?

I am making a Web Browser , I have done some parts like that new tab Page,Bookmark,home page,Default Search Engine and so on. I'm confused about how to closed the TAB PAGE. I have tried Double click , Mouse down, up and many more but I can't solve the problem. I have create the TABPAGE like that . Thanks in advance waiting reply.....

 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (tabControl1.SelectedTab.Text == "+")
        {
            AddNewTab();
        }
        foreach (Control item in tabControl1.SelectedTab.Controls)
        {
            if (item.GetType() == typeof(WebBrowser))
            {
                WebBrowser wb = (WebBrowser)item;
                toolStripButton1.Enabled = wb.CanGoBack;
                toolStripButton2.Enabled = wb.CanGoForward;
            }
        }

Snapshot my Window form application

enter image description here

Upvotes: 2

Views: 407

Answers (3)

LarsTech
LarsTech

Reputation: 81610

Just try disposing of the TabPage. Assuming a button called "Close Tab" on the form:

private void closeTab_Click(object sender, EventArgs e) {
  if (tabControl1.SelectedTab != null) {
    tabControl1.SelectedTab.Dispose();
  }
}

Upvotes: 2

Deep in the Code
Deep in the Code

Reputation: 572

If you have more than one tab, changing tabs should fire the code. Does your markup have runat="server" in the tag declaration?

Upvotes: 0

user1193035
user1193035

Reputation:

You will need Javascript to do this. Use window.close():

close();

Note: the current window is implied. This is equivalent:

window.close();

or you can specify a different window.

So:

function close_window() {
  if (confirm("Close Window?")) {
    close();
  }
}

with HTML:

<a href="javascript:close_window();">close</a>

or:

<a href="#" onclick="close_window();return false;">close</a>

You return false here to prevent the default behavior for the event. Otherwise the browser will attempt to go to that URL (which it obviously isn't).

Now the options on the window.confirm() dialog box will be OK and Cancel (not Yes and No). If you really want Yes and No you'll need to create some kind of modal Javascript dialog box.

Note: there is browser-specific differences with the above. If you opened the window with Javascript (via window.open()) then you are allowed to close the window with javascript. Firefox disallows you from closing other windows. I believe IE will ask the user for confirmation. Other browsers may vary.

Upvotes: 0

Related Questions