I use a LabelLink contorl in a WinForm.
On form load I set the desired link:
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
On click :
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData as string);
}
The link is gray and nothing happens when I click on it.
What is missing?
Try this
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
this.linkLabel1.Links[0].LinkData = "Ask a question";
linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked);
and
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url;
url = e.Link.LinkData.ToString();
if (!url.Contains("://"))
url = "http://" + url;
var myLink = new ProcessStartInfo(url);
Process.Start(myLink);
linkLabel1.LinkVisited = true;
}
Related
I have crate a registry at user system. And i want when user click on my image button that is in my gridview. I shall call url protocol from registry and execute the Explorer.exe with path that i will assign with the image button on the grid.
I create registry that is below
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\PicPath]
#="URL: MPath Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\PicPath\shell]
[HKEY_CLASSES_ROOT\PicPath\shell\open]
[HKEY_CLASSES_ROOT\PicPath\shell\open\command]
#="\"C:\\Windows\\explorer.exe\""
the problem is that when i add
#="\"C:\\Windows\\explorer.exe\ " "%1
%1 is for parameter when i pass c:\Logs my system start to open infinite explorer in taskbar. But when i use #="\"C:\\Windows\\explorer.exe\"" its open explore perfect on client system. But i want that explorer.exe open certain path on client system.
below is my code that i try
protected void grdOrderList_RowDataBound(object sender, GridViewRowEventArgs e)
{
HtmlAnchor a = new HtmlAnchor();
a.HRef = "MPath:OpenForm " + "/root,C:\\Abc";
a.ID = "a1";
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ID = "img1";
img.Visible = true;
img.ImageUrl = #"~\images\blue_camera.png";
a.Controls.Add(img);
e.Row.Cells[0].Controls.Add(a);
}
So how can i do this . Thanks for you time
protected void grdOrderList_RowDataBound(object sender, GridViewRowEventArgs e)
{
HtmlAnchor a = new HtmlAnchor();
a.HRef = "MPath:OpenForm " + "/root,C:\\Abhishek";
a.ID = "a1";
//System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
//img.ID = "img1";
//img.Visible = true;
//img.ImageUrl = #"~\images\blue_camera.png";
var img = new ImageButton();
img.Click += new ImageClickEventHandler(img_Click);
a.Controls.Add(img);
e.Row.Cells[0].Controls.Add(a);
}
protected void img_Click(object sender, ImageClickEventArgs e)
{
System.Diagnostics.Process.Start(#"c:\blah.txt");
}
Okay. So, I'm making my own internet browser and I have tabs. But, I'm trying to make it a real time url updater while if you click on any link it will show up in the textbox of the url.
It will not work.
Here is the tab button.
private void button8_Click(object sender, EventArgs e)
{
WebBrowser Browser = new WebBrowser();
tabControl1.TabPages.Add("New Page");
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
Browser.Name = "Web Browser";
Browser.Dock = DockStyle.Fill;
tabControl1.SelectedTab.Controls.Add(Browser);
((WebBrowser)(tabControl1.SelectedTab.Controls[0])).GoHome();
And here is where my textbox isn't getting the right url.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
button1.Enabled = true;
textBox1.Enabled = true;
//textBox1.Text = Browser.Url.ToString();
((WebBrowser) (this.tabControl1.SelectedTab.Controls[0])).Url.ToString();
}
In order for this to work, you need to get all link elements of the web page you've just loaded and assign a custom function to the HtmlElement.Click event of that element.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
button1.Enabled = true;
textBox1.Enabled = true;
var linkElements = Browser.Document.GetElementsByTagName("a");
foreach(HtmlElement link in linkElements)
{
link.Click += (s, args) =>
{
// a link is being clicked
// get the url the link is pointing to using the href attribute of the element
textBox1.Text = link.GetAttribute("href");
}
}
}
I am building an app in windows phone 7 where i need to add an event reminder. On clicking a button the reminder should be set. My cs file is:
namespace KejriwalPhoneApp
{
public partial class EventDetails : PhoneApplicationPage
{
public EventDetails()
{
InitializeComponent();
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBarIconButton home = new ApplicationBarIconButton();
home.IconUri = new Uri("/Image/icon_home_deselect.png", UriKind.Relative);
home.Text = "Home";
ApplicationBar.Buttons.Add(home);
home.Click += new EventHandler(home_Click);
ApplicationBarIconButton share = new ApplicationBarIconButton();
share.IconUri = new Uri("/Image/icon_share_deselect.png", UriKind.Relative);
share.Text = "Share";
ApplicationBar.Buttons.Add(share);
share.Click += new EventHandler(share_Click);
ApplicationBarIconButton news = new ApplicationBarIconButton();
news.IconUri = new Uri("Image/icon_news_deselect.png", UriKind.Relative);
news.Text = "News";
ApplicationBar.Buttons.Add(news);
news.Click += new EventHandler(news_Click);
ApplicationBarIconButton events = new ApplicationBarIconButton();
events.IconUri = new Uri("/Image/icon_event_deselect.png", UriKind.Relative);
events.Text = "Video";
ApplicationBar.Buttons.Add(events);
events.Click += new EventHandler(events_Click);
}
void events_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
void news_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/News.xaml", UriKind.Relative));
}
void share_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/share.xaml", UriKind.Relative));
}
void home_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
private void Image_Back(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var imagePath = "";
var eventdate = "";
var location = "";
var utimee = "";
var tzone = "";
var ename = "";
var desc = "";
//check if particular parameter available in uri string
if (this.NavigationContext.QueryString.ContainsKey("image_path"))
{
//if it is available, get parameter value
imagePath = NavigationContext.QueryString["image_path"];
eventimage.Source = new BitmapImage(new Uri(#"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/" + imagePath, UriKind.Absolute));
}
if (this.NavigationContext.QueryString.ContainsKey("Time_Zone"))
{
tzone = NavigationContext.QueryString["Time_Zone"];
timezone.Text = tzone;
}
if (this.NavigationContext.QueryString.ContainsKey("uTime"))
{
utimee = NavigationContext.QueryString["uTime"];
utime.Text = utimee;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Date"))
{
//if it is available, get parameter value
eventdate = NavigationContext.QueryString["Event_Date"];
evntdate.Text = eventdate;
}
if (this.NavigationContext.QueryString.ContainsKey("Location"))
{
//if it is available, get parameter value
location = NavigationContext.QueryString["Location"];
loc.Text = location;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Name"))
{
//if it is available, get parameter value
ename = NavigationContext.QueryString["Event_Name"];
enamee.Text = ename;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Description"))
{
//if it is available, get parameter value
desc = NavigationContext.QueryString["Event_Description"];
edescription.Text = desc;
}
}
private void Image_Previous(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
private void Image_rem(object sender, RoutedEventArgs e)
{
RegisterReminder();
}
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = beginDateTime;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}
}
}Now when the reminder button is clicked i want the fields utimee, tzone to be set and i get a pop up message "Event reminder added successfully"
I am not getting the idea on how to do this
You can do these steps:
1.get the values from webservice as global variable:
eventDate,location, utimee, tzone, ename,desc.
2.click the reminder button, execute the click method
private void BtnReminderClick(object sender, EventArgs e)
{
RegisterReminder();
}
3.do reminder register
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = DateTime.Parse(eventDate).Date + DateTime.Parse(utimee).TimeOfDay;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}
I'm programming an algorithm in C# to download an image from a website and my software automatically fills all the required fields and presses the download button. The problem is that I'm not able to load the image. The dialog box to download image on Internet Explorer is appearing, so I need to get the url of the picture after clicking the button "generate" and load it into the picture box. My code:
private void simpleButton6_Click(object sender, EventArgs e)
{
string i = "0";
HtmlElement hu = webBrowser3.Document.GetElementById("data-text");
hu.Focus();
hu.SetAttribute("Value", txtEncodeData.Text);
HtmlElement hu1 = webBrowser3.Document.GetElementById("color");
hu1.Focus();
Color c = customColorBlender1.SelectedColor;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
hu1.SetAttribute("Value", hex);
HtmlElement hu2 = webBrowser3.Document.GetElementById("effect");
hu2.Focus();
if (comboBoxEdit1.SelectedIndex == 1)
{
i = "1";
}
hu2.SetAttribute("Value", i);
webBrowser3.Document.GetElementById("generate").InvokeMember("click");
t.Interval = 1000;
t.Start();
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
String url = Convert.ToString(webBrowser3.Document.GetElementById("download").InvokeMember("click"));
MessageBox.Show(url);
pictureBox15.ImageLocation = Convert.ToString((Uri)webBrowser3.Document.GetElementById("download").InvokeMember("click"));
}
I am getting an error "Object Reference is not set to an Instance of an object" in the ContentPage of my MasterPage Facebook Application.
Site.master.cs
public FacebookSession CurrentSession
{
get { return (new CanvasAuthorizer()).Session; }
}
protected void Page_Load(object sender, EventArgs e)
{
var auth = new CanvasAuthorizer { Perms = "email,read_stream,publish_stream,offline_access,user_about_me" };
if (auth.Authorize())
{
ShowFacebookContent();
}
}
private void ShowFacebookContent()
{
var fb = new FacebookClient(this.CurrentSession.AccessToken);
dynamic myInfo = fb.Get("me");
lblName.Text = myInfo.name;
imgProfile.ImageUrl = "https://graph.facebook.com/" + myInfo.id + "/picture";
lblBirthday.Text = myInfo.birthday;
pnlHello.Visible = true;
}
This master Page works OK & displays UserName & ProfilePic.
Default.aspx.cs
SiteMaster myMasterPage;
protected void Page_Load(object sender, EventArgs e)
{
myMasterPage = this.Page.Master as SiteMaster;
}
public void LinkButton1_Click(object sender, EventArgs e)
{
var fb = new FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
dynamic feedparameters = new ExpandoObject();
feedparameters.message = (message_txt.Text == null ? " " : message_txt.Text);
feedparameters.user_message_prompt = "userPrompt";
/*Dictionary<string, object> feedparameters = new Dictionary<string, object>();
feedparameters.Add("message", "Testing Application");
feedparameters.Add("user_message_prompt", "Post To Your Wall");
feedparameters.Add("display", "iframe");*/
dynamic result = fb.Post("me/feed", feedparameters);
}
Even this Page Loads OK but Problem comes when I try to Post using LinkButton.
Following Line gives the error.
var fb = new FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
On LinkButton Click Object Reference is not set to an Instance of an object...
I will really appreciate some help.
Wel finally found what was the problem. Needed to add a hidden field.
<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>
I think this is neither mentioned any where in the documentation nor in the Provided Samples.