how can closed the TAB page by click? - c#

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

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();
}
}

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:
close
or:
close
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.

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

Related

How can I disable (grey out) specific tabpage(s) of a tab control programatically in my C# form app?

I can't believe that disabling specific tabpages (visible but greyed out that means not clickable) is not possible in Visual Studio C# Form app. I have found just a workaround that I couldn't bring to work.(See link below)
I wanted to ask this question again, because perhaps there is another solution/workaround in the meantime.
How to highlight/grey-out Tabcontrol Tabpage
For just making the tab nonclickable (what is also OK for me) I have used this code, but not working
private void tabControl1_Selecting(object sender,TabControlCancelEventArgs e)
{
if (!e.TabPage.Enabled)
{
e.Cancel = true;
}
}
For example if you want to disable tabPage2 use this code in form load event. It will not show in intellisense but you can type.
tabPage2.Enabled = false;
Then use tab control selecting event like this
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPageIndex < 0) return;
e.Cancel = !e.TabPage.Enabled;
}

How do I specify the default button of a TextBox that is referred to by AcceptsReturn?

I have a windows form with a tool strip on it containing a text box and some buttons (think browser url bar with a go button, back, forward)
I want pressing enter to activate the goButton just as clicking it would, which I believe is what TextBox.AcceptsReturn = false is for.
I don't see anything that seems to fit the bill for "tell me what button on the form is the one that we will activate".
What am I missing?
A Form has a default button, but a specific control does not (out of the box anyway).
In your scenario, I would probably handle invoking the goButton.Click event by monitoring the keys pressed waiting for the Enter key to be pressed.
The easiest way is to set the forms "Accept Button" to the button control you want. This can be done in the designer.
I know this is an Old Question, but for someone who might to to lazy or just a beginner ,
handler might look like too much work ( though it isn't really )
But there is an easier work around for this,
you can make a panel for each of them ( 1 Textbox and 1 Button for Example ) , and set the Defaultbutton for Each panel as you need.
I used this for my site, where I had several Ajax panel , and I Wanted Each to have their own search box on different subjects and work with Enter Button.
Looks like an old question, but I will provide my solution.
private void ChangeDefaultButton()
{
if (this.TextBox.Focused)
{
this.AcceptButton = button;
}
else
{
this.AcceptButton = button1;
}
}
And then add this method to the Focus Events of the text boxes. Like...
private void TextBox_Enter(object sender, EventArgs e)
{
ChangeDefaultButton();
}
And
private void TextBox_Leave(object sender, EventArgs e)
{
ChangeDefaultButton();
}

How to close Find window in a webbrowser control

I use a WebBrowser control and it's find functionality:
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.Select();
SendKeys.Send("^f");
}
Which works fine. Only problem that there is a case when user can make WebBrowser unvisible to perform some other tasks:
webBrowser1.Visible = false;
But Find window remains visible. Any suggestions?
Thank you.
To close, try this
webBrowser1.Select();
SendKeys.Send("^f");
SendKeys.Send("{ESCAPE}");
There is no easy/direct way to control the Find dialog. One way to close the Find dialog is by sending "ESCAPE" to the dialog when it has focus. If you send "^f" prior to sending "ESCAPE", that will force the find dialog to get focus.

Focusing WebBrowser control in a C# application

I have a WebBrowser control hosted in a windows Form. The control is used to display hyperlinks which get created at runtime. These links point to some HTML pages and PDF documents.
The problem is that when the form hosting the browser control is loaded, the focus is on the form. When the TAB key is pressed, the focus does not shift to the first hyperlink. However, if I perform a mouse click on the control and then hit the TAB key, the tab focus is now on the first hyper link. I tried using Select() on the WebBrowser control and then I called Focus(), but it doesn't solve the problem.
Any ideas on how to set the tab focus on the first hyperlink at load? Thanks.
Cheers,
Harish
I guess it might be because the focus is set before the page is fully loaded. Try this:
private void Go(string url)
{
webBrowser1.Navigate(url);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Body.Focus();
}
You could also automatically select the focus on the first link directly by getting the HtmlElement of that first link.
If the above doesn't work, you might want to check other parts of your code to see if anything else is capturing the focus. Try searching for Select, Focus and ActiveControl in your code.
Use form.ShowDialog(form) instead on form.Show(), then it will work !
where form is the running instance of your windows Form
This is my solution
private void txtAdres_KeyPress(object sender, KeyPressEventArgs e)
{
int licznik = 1;
if (e.KeyChar == (char)13)
{
string adres = txtAdres.Text;
webBrowser1.Navigate(adres);
licznik = 0;
}
if (licznik == 0)
{
webBrowser1.Focus();
}
}
In a normal scenario it should be sufficient for you to set the TabIndex of the WebBrowser control to zero. This way, when the form loads the control will be focused and pressing TAB will iterate through the links.
Note that you should also change the TabIndex of the other controls on the form.
If this does not solve your problem, you need to add more detail on the complexity of the form hosting the control.

how to set a TabControl tab to be invisible

In C# using VS2005 I have a Winforms TabControl with 7 tabs, but I want the last tab to be only visible if a certain configuration option is set.
How to make the TabControl only show the first six tabs? In other words, how do I make the seventh tab not visible?
private void HideTab(object sender, EventArgs e)
{
this.tabControl1.TabPages.Remove(this.tabPage2);
}
private void ShowTab(object sender, EventArgs e)
{
this.tabControl1.TabPages.Add(this.tabPage2);
}
this.tabPage2 is your 7th tabpage, whatever name you give it.
No its not possible to hide a tab in tabcontrol. If you are adding the tabs ar run time then dont add 7th tab if condition not satisfied.
If you done in design time then remove the tab if condtion failed.
yourTabControl.TabPages.Remove(tabPageName);
you can implement a property
public bool TabVisible
{
get
{
return tabControl1.Contains(tabPage2);
}
set
{
if(value == TabVisible) return;
if(value)
tabControl1.TabPages.Add(tabPage2);
else
tabControl1.TabPages.Remove(tabPage2);
}
}
you should also overwrite your disposing function,
you can move out the Dispose function from the designer generated code to your own code, the designer notices that. you see that the components.Dispose(); function can not reach the tabPage any more for disposal, so you need to dispose it manually if it has not been disposed. otherways, especially if you are opening your window many times, you run out of window handles

Categories

Resources