I have making the Tab Document Interface like that Firefox. I want to make a some portion of the page refresh Time to Time. I think have you seen already Cricket Page Refresh page after some time. I have used panel for the refresh for page but panel not show. I have try but can't do this.I am working at windows form. plz any body solve this problem and thanks in advance. My coding part here:-
private void Form1_Load(object sender, EventArgs e)
{
AddNewTab();
toolStripTextBox1.Text = "Go to website";
toolStripTextBox2.Text = "Google Search text here";
toolStripComboBox1.Text = "Google.co.in";
toolStripComboBox1.Items.Add("Google.co.in");
timer1.Enabled = true;
timer1.Start();
panel1.Show();
label1.Text = DateTime.Now.ToString();
}
TabPage tp;
WebBrowser wb;
private void AddNewTab()
{
tp=new TabPage();
wb=new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb.Focus();
wb.Url = new Uri("http://google.co.in");
wb.Dock=DockStyle.Fill;
tp.Controls.Add(wb);
tabControl1.TabPages.Insert(tabControl1.TabPages.Count - 1, tp);
tabControl1.SelectedTab = tp;
}
Related
hello I have a problem with TabControl. When I open the second Form it is always empty with no controls or anything.
my code. When I open the first tabpage everything is fine. Everything is in place
private void ShowFormInTabPage(TabPage tp , Form frm)
{
tabControl1.Controls.Add(tp);
frm.TopLevel = false;
tp.Text = frm.Text;
frm.Visible = true;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
tabControl1.TabPages[0].Controls.Add(frm);
}
I add form to tabcontrol through such a method. the methods are the same in both cases
private void guna2Button1_Click(object sender, EventArgs e)
{
_tpEmployees = new TabPage();
if (EmployeesForm.IsNull)
{
ShowFormInTabPage(_tpEmployees , EmployeesForm.Instance);
}
else
{
tabControl1.SelectedTab = _tpEmployees;
}
I am using CefSharp to create a browser. It is working, I can navigate to various websites by using new tab. But when I click on previous tabs, all the tab shows same URL in the address bar and all of them has exactly same title. Here is my code:
private void FormBrowser_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
ChromiumWebBrowser browser = new ChromiumWebBrowser(toolStripTextBoxAddress.Text);
browser.Parent = tabControl.SelectedTab;
browser.Dock = DockStyle.Fill;
browser.AddressChanged += Browser_AddressChanged;
browser.TitleChanged += Browser_TitleChanged;
}
// new tab function
public void addNewTab()
{
TabPage tpage = new TabPage();
tpage.Text = "New Tab";
tabControl.Controls.Add(tpage);
tabControl.SelectTab(tabControl.TabCount - 1);
toolStripTextBoxAddress.Text = "";
ChromiumWebBrowser browser = new ChromiumWebBrowser(toolStripTextBoxAddress.Text);
browser.Parent = tpage;
browser.Dock = DockStyle.Fill;
browser.AddressChanged += Browser_AddressChanged;
browser.TitleChanged += Browser_TitleChanged;
}
private void Browser_TitleChanged(object sender, TitleChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
tabControl.SelectedTab.Text = e.Title;
}));
}
private void Browser_AddressChanged(object sender, AddressChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
toolStripTextBoxAddress.Text = e.Address;
}));
}
// navigate method
private void toolStripTextBoxAddress_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (!string.IsNullOrEmpty(toolStripTextBoxAddress.Text))
{
if (!toolStripTextBoxAddress.Text.Contains("."))
{
getCurrentBrowser().Load("http://www.google.com/search?q=" + toolStripTextBoxAddress.Text);
}
else
{
getCurrentBrowser().Load(toolStripTextBoxAddress.Text);
}
}
}
}
// get current browser
private ChromiumWebBrowser getCurrentBrowser()
{
return (ChromiumWebBrowser)tabControl.SelectedTab.Controls[0];
}
// new tab button
private void toolStripButtonNewTab_Click(object sender, EventArgs e)
{
addNewTab();
}
Here is what I have tried:
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
{
ChromiumWebBrowser currentBrowser = getCurrentBrowser();
toolStripTextBoxAddress.Text = currentBrowser.Address;
}
When i try to open a new tab it is giving me an error in this line return (ChromiumWebBrowser)tabControl.SelectedTab.Controls[0];
How can I solve this problem? Thanks in advance.
I wrote my multi-tab cefsharp code in a very similar fashion to yours, and encountered the same error.
It was cause by the default number of tab pages. (When you drag tabcontrol to your form, it by default comes with 2 tabpages to start with). From the property panel, I removed those two tabpages, so that the browser starts wit zero tabpage. Any tabpage is only added when you start browsing, by inputting url or clicking favorites.
If you do not set the initial number of tabpages to zero, those two "empty" tabpages have no browser attached to them. Therefore the getcurrentbrowser() function fails to find any browser on those empty tabpages and errors occur.
I want to program a screensaver and since I already have the HTML5 Code I just want to use a WebBrowser Control which renders the content. However I can't figure out how to exit the application on events like "Click", "Keydown", etc. WebBrowser class doesn't seem to know those events. Can anyone tell me how I can make my application exit?
Here's some code:
public Screensaver()
{
InitializeComponent();
this.Load += Screensaver_Load;
StartBrowser();
}
private void StartBrowser()
{
this.webBrowser1.DocumentText = Content;
}
private void Screensaver_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
Cursor.Hide();
this.TopMost = true;
this.BackColor = Color.White;
this.webBrowser1.Size = new System.Drawing.Size(this.ClientSize.Width, this.ClientSize.Height);
}
private String Content
{
get
{
return "<html>..[long html code following]..</html>";
}
}
you can use javascript function to close current application in browser for example:
close
I have created two buttons close and new tab and a web browser which loads google. When I click new tab it opens the new tab but doesn't open a web browser.
Here's the code I have so far which is from the Microsoft help site. I'm using Visual Studio 2012 with c#.
private void newTab_Click(object sender, EventArgs e)
{
string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
}
private void closeTab_Click(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
At the moment I have this code but when I type in the search box it only works in tabpage 1
and not in any of the new tabs that I open so I need to add some code to the searchbox?
my code is:
private void newTab_Click(object sender, EventArgs e)
{
string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
var browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.Url = new Uri(#"http://www.google.com");
myTabPage.Controls.Add(browser);
tabControl1.TabPages.Add(myTabPage);
}
You are missing webbrowser control in your code:
private void newTab_Click(object sender, EventArgs e)
{
string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
WebBrowser wb = new WebBrowser();
myTabPage.Controls.Add(wb);
wb.Navigate("google.com");
}
private void closeTab_Click(object sender, EventArgs e)
{
if(tabControl1.TabPages.Count == 1)
return;
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
You also have to add a new instance of the WebBrowser control to your tab:
private void newTab_Click(object sender, EventArgs e)
{
string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
// Create new WebBrowser instance
var browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.Url = new Uri(#"http://www.google.de");
// Add the WebBrowser control to the TabPage.
myTabPage.Controls.Add(browser);
tabControl1.TabPages.Add(myTabPage);
}
Each TabPage is initially empty, just like it is if you would have added it using the designer. It's content depends on what you want to add. Sharing a WebBrowser-Control does not make sense, since you want to open different websites on different tabs, I guess.
In case you do not want the user to close the first tab you can simply check if the tab the user requests to close is the first one created:
private void closeTab_Click(object sender, EventArgs e)
{
// Is the Tab Page the first one?
if (tabControl1.SelectedTab == tabControl1.TabPages[0])
return;
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
Or in case you want at least one tab page to stay "open" you can use the TabCount-Property:
private void closeTab_Click(object sender, EventArgs e)
{
// Is the Tab Page the last one opened?
if (tabControl1.TabCount == 1)
return;
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
I want to recreate a simple browser with tab capability. A new tab has to be created every time the user clicks on "button_addTab" or when the selected web site tries to open a new window.
Here is my code:
Add a new tab by pressing the dedicated button:
private void button_addTab_Click(object sender, EventArgs e)
{
TabPage addedTabPage = new TabPage("tab title"); //create the new tab
tabControl_webBrowsers.TabPages.Add(addedTabPage); //add the tab to the TabControl
WebBrowser addedWebBrowser = new WebBrowser()
{
Parent = addedTabPage, //add the new webBrowser to the new tab
Dock = DockStyle.Fill
}
addedWebBrowser.Navigate("www.google.com");
Prevent a site from opening new windows (if you know every webBrowsers name) :
private void specificWebBrowser_NewWindow(object sender, CancelEventArgs e)
{
WebBrowser thisWebBrowser = (WebBrowser)sender;
e.Cancel = true;
TabPage addedTabPage = new TabPage("tab title");
tabControl_webBrowsers.TabPages.Add(addedTabPage);
WebBrowser addedWebBrowser = new WebBrowser()
{
Parent = addedTabPage,
Dock = DockStyle.Fill
}
addedWebBrowser.Navigate(thisWebBrowser.StatusText.ToString());
}
Now my question is:
How can I modify the second branch of code in order to match all the web browsers created with no names when the first code is called (at one time)?
Try to modify the first function to attach an event handler to newly created browser:
private void button_addTab_Click(object sender, EventArgs e)
{
TabPage addedTabPage = new TabPage("tab title"); //create the new tab
tabControl_webBrowsers.TabPages.Add(addedTabPage); //add the tab to the TabControl
WebBrowser addedWebBrowser = new WebBrowser()
{
Parent = addedTabPage, //add the new webBrowser to the new tab
Dock = DockStyle.Fill
};
addedWebBrowser.NewWindow += specificWebBrowser_NewWindow;
addedWebBrowser.Navigate("www.google.com");
}