I'm looking for a way to use hyperlinks in a winforms environment.
I found that it uses System.Web.UI.WebControls; but when i tried to use it in my program System.Web was as far as it would go.
So I checked the refrences but also no System.Web.UI.WebControls or something like that,
any sugestions?
You can use LinkLabel control. Set text property of LinkLabel to show your web link. You can use "LinkClicked" event to open the web browser as shown below. Hope this helps you.
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(linkLabel1.Text);
}
If your're developing a WinForms application you have to use System.Windows.Forms.LinkLabel control, located in System.Windows.Forms assembly. Controls in System.Web.* are for HTML pages.
If it's WPF you can do something like this:
<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
Click here
</Hyperlink>
</TextBlock>
And in the code-behind:
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
It will look like this:
Related
I want to be able to tell when the user cliked on a textbox and is in "edit" mode. Everywhere I look I see the textbox_Enter and textbox_Leave events being used with the instructions within that and it works fine. For me however it doesn't do anything. I tried elimination as many outside factors as possible, including creating a brand new project just for testing purposes and copied some code samples yet again nothing happens when I click on the textbox. I'm using Visual Studio 2017 on Windows 10 with Visual C# Application Windows Form (.NET Framework)
Also here's a sample of the code I try to use if it helps for whatever reason
private void textbox_Enter(object sender, ControlEventArgs e)
{
label.Text = "ok";
}
First of all the type of the e parameter is not correct: It must be EventArgs, not ControlEventArgs:
private void textbox_Enter(object sender, EventArgs e)
{
// Do something
}
Second, you need to register the event in the forms designer with the textbox control in the properties window:
You need to wire up this method to the textbox enter event. Select the control and then look at the events section in the properties tab.
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;
}
I am asking for a user to type in what he or she would like to search for, and then I would like to pass this value to another page where the search will be performed and the results will be given. I am using a PhoneTextBox control from the WP Toolkit. On the KeyUp or ActionIconTapped event I would like to get the value entered in the PhonTextBox and pass that to my search page, although I cannot figure out how to get the text value entered?
MainPage.xaml
<toolkit:PhoneTextBox x:Name="publicSearchTextBox" HorizontalAlignment="Stretch" Margin="-10,0,12,0"
Hint="search for topic or name"
ActionIcon="/Resources/Images/search.png"
ActionIconTapped="publicSearchTextBox_ActionIconTapped"
KeyUp="publicSearchTextBox_KeyUp"/>
MainPage.xaml.cs
..get publicSearchTextBox text value and pass this to the search page?
For some reason, I cannot reference the PhoneTextBox in my code behind from setting x:Name="publicSearchTextBox" in my xaml? How is this possible?
Perhaps you have a typo because i made some handlers for the XAML you have above and it works fine for me. Copy paste the following in the code behind and try?
private void PrintTextboxValue()
{
Debug.WriteLine("Value: {0}", publicSearchTextBox.Text);
}
private void publicSearchTextBox_ActionIconTapped(object sender, EventArgs e)
{
PrintTextboxValue();
}
private void publicSearchTextBox_KeyUp(object sender, KeyEventArgs e)
{
PrintTextboxValue();
}
If it does not work then please update your question with more information such as, where you are referencing the PhoneTextBox.
I'm using both winform and incorporating wpf through ElementHost.
How can I call a WPF ICommand from a Winforms button's click event? These are all new to me so bear with me with these kind of questions.
My current code is
CarView car = (CarView) CarHost.Child;
CarViewModel cvm = (CarViewModel) car.DataContext;
cvm.SaveCommand.Execute(null);
So by doing that I was able to call the SaveCommand, but I dont get any data.
Thanks in advance.
I might be missing something here. Normally you'd do something like:
<Button Command="{Binding MyCommand}" />
And then when someone clicks the button, MyCommand's Execute method is called.
I suppose, from a codebehind, you could call:
private void OnClick(object sender, RoutedEventArgs e)
{
if (MyCommand.CanExecute(null))
MyCommand.Execute(null);
}
But except for very specific circumstances (which you haven't mentioned) I'm not sure why you'd do it that way. I think you definitely need to give us a little more information.
I just searched, but didn't find a way to create a web link in my Windows phone7 Application. In Android TextView has android:autoLink='Web' In Windows phone7 textblock I didn't find any relevant property.
Tried adding the NavigateURI property in the Hyperlink and it gives an exception. NavigateUri="http://www.google.com"
Really appreciate If someone Can suggest How to do this. Thanks in Advance...!!!!!
Use just the HyperLinkButton Control.
And add this property to your control:
<HyperlinkButton TargetName="_blank" Content="Go To" Click="HyperlinkButton_Click"/>
Finally add the click event handler to launch the browser using the BrowserTask :
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.google.com");
webBrowserTask.Show();
}