Open Links In Another TabPage WebControl - c#

I have a tabControl with two tabPages each with their own Awesomium WebConrol. I need links from one WebControl to open in the other WebControl. I'm currently using VS 2012.
How would that work? Is it even possible to do?

You need to add target="_blank" to your links. This way you will be able to capture webControl.ShowCreatedWebView event. In this event you will have target link e.TargetURL. You can load it to another webControl object, like in initialisation.
Your link:
Link
Your code (webControl1 in first tab, this.webControl2 in second):
this.webControl1.ShowCreatedWebView += this.webControl1_ShowCreatedWebView;
private void webControl1_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
webControl2.Source = e.TargetURL;
}

Related

How to make a button on/off switch?

Using VS2013, C#, .Net and Winforms how can I make a regular Button look "pressed"? Imagine this button is an on/off switch. ToolStripButton has the Checked property, but the regular Button does not.
Are you really forced to use a button or does it just have to look like one? For the latter you can just use a checkbox with the Appearance set to Button and Checked=true. This will make the checkbox appear like a button which is clicked.
If it is a custom requirement i.e. the button you need does not exist in the regular controls, I suggest you create a custom control button for your needs. Here is a link of a tutorial to create a custom control : How to: Create a Custom Image Button Control
You can also use a third party control like : Telerik Button - Radios and Checkboxes
Once the files are available to your site, activating the script is very easy:
...
$(document).ready(function() {
$(':checkbox').iphoneStyle();
});
You can change button's background image or background color in button click event handler.
Decalre somewhere in your code :
bool isClicked = false;
In event handler you can do :
private void button1_click(object sender, EventArgs e)
{
Button btn = sender as Button;
isClicked = !isClicked;
btn.BackgroundImage = isClicked? image1 : image2; // or use BackColor
}
There is a better and elegant solution. You can take a look how .NET draws it itself and try to do the same.
You should basically use
System.Windows.Forms.ButtonRenderer
class for drawing buttons in different states (Pressed, Hover etc.)
Please try to avoid using images for displaying states because to do it correctly, you would need to support different DPIs, sizing, proportions and so on. Rely on standard Render* classes fist.

How to use same textbox with other tabs on the tabcontrol?

Sorry for the simple question and also sorry if there is an answer on the site and I couldn't find.
I want to use same textbox in every tab that I use on my form. How can I do that?
Add this to the TabControl's SelectedIndexChanged event handler.
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Add(textBox1);
}
Adding a control to one tab page's Controls collection automatically removes it from the others.
Note: I have tested it by adding two lables on the form above the tab control and added these two lines to the method shown above:
label1.Text = tabControl1.TabPages[0].Controls.Count.ToString();
label2.Text = tabControl1.TabPages[1].Controls.Count.ToString();
Put the TextBox in the parent control of the TabControl. It can hover over all the rest. You might need to rework the focus traversal though.

how to execute code when the tab index changes?

I currently have a tabcontrol on my windows form in visual studio, i would like it so that when the user clicks on a different tab that i can execute some code (for example populate a listbox).
when i double click on the tab it only brings up an onclick event for the body of the tabcontrol.
i was thinking that i may have to create a thread in the form load that will constantly check whether the tab index changes and if it does then execute some code. but surely there must be an easier way?
You can use TabControl.Selecting or TabControl.SelectedIndexChanged event
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
//Your code goes here.
}
You should look at TabControl events
http://msdn.microsoft.com/en-ie/library/system.windows.forms.tabcontrol.selecting.aspx

Adding controls to tab page runtime

I am using C# and winForms, I have a few tabcontrols, which contains a few tab pages,
I would like to add all tab pages my user control, it would be best, If I could add it after user click on tab page. It works for me only, when I add this controls in constructor - what makes delay at application start - about 3 seconds, what is very much.
I would like to add this controls at run time, like
tabPage1.onClickEvent()
{
tabPage1.Controls.Add(myUserControl);
}
but it didnt works, I also tryied to use Invalidate, or Refresh method but it not works.
So is there any possibility to add this userControls in other method than constructor?
Maybe its problem, that I have TabControl inside TabControl and I have to add this controls throught parent TabControl?
Thanks!
Try double clicking the tag page in the designer, or you can add the event handler manually like this:
tabPage1.Click += new EventHandler(tagPage1_Click);
I don't know whether tabPage1 is dynamic, but if it's not, you should add the above event handler to your designer.cs file.
Here is the event handler in the code:
protected void tabPage1_Click(object sender, EventArgs e)
{
tagPage1.Controls.Add(new TextBox());
}

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.

Categories

Resources