Post by bobowk on Feb 28, 2017 19:46:36 GMT 10
So guys, I was wondering how I could rename bookmarks such as 'http://www.google.com' to 'Google', but when they click it, it navigates to 'http://www.google.com/' Like in Google Chrome. Is there also a way to add favicons to the toolstrip? Here is my code right now to add the bookmark:
private void bookmarks_Click(object sender, EventArgs e)
{
ToolStripItem item = new ToolStripMenuItem();
item.Text = urlTextBox.Text;
item.Name = "Navigate to Bookmark";
linkBar.Items.Add(item);
} Although it isn't as good and it is too long. How can I also save the bookmarks? Thanks!
|
|
Post by Imformas on Feb 28, 2017 19:52:22 GMT 10
Just use the "Tag" object on any control or class from "System.Windows.Forms" reference. Thats why its there, to store data for use man aha private void bookmarks_Click(object sender, EventArgs e) { ToolStripItem item = new ToolStripMenuItem(); item.Text = "Website title" item.Name = "Navigate to Bookmark"; item.Tag = "website url"; item.Click += (senderObject, eventArgs) => { ToolStripItem toolItem = (ToolStripItem)senderObject; string url = (string)toolItem.Tag;
// your code here // url will return the specified items, Tag object as string value.
} linkBar.Items.Add(item); }
Programming language'sCSharpC++CObjective-CVBProject'sSharpMediaSharpEditYoutifygithub.com/Stephen-Fox-0
|
|
Post by bobowk on Mar 1, 2017 6:57:31 GMT 10
ImformasHow would I be able to use the item declaration in the click void?
|
|
Post by bobowk on Mar 1, 2017 6:57:52 GMT 10
Imformas private void bookmarks_Click(object sender, EventArgs e) { ToolStripItem item = new ToolStripMenuItem(); item.Text = ParentTabs.SelectedTab.Caption; item.Name = urlTextBox.Text; item.Tag = urlTextBox.Text; item.Click += (senderObject, eventArgs) => { ToolStripItem toolItem = (ToolStripItem)senderObject; string url = (string)toolItem.Tag; }; linkBar.Items.Add(item); }
void item_click(object sender,EventArgs e) { }
|
|
Post by Imformas on Mar 1, 2017 15:45:34 GMT 10
You can either use public void item_Click(object sender, EventArgs e) {} or use a single delegate in current void, using this way, you can reassign the event to a different one, but using it the same way! item.click += (sender, e) => { }
Programming language'sCSharpC++CObjective-CVBProject'sSharpMediaSharpEditYoutifygithub.com/Stephen-Fox-0
|
|
Post by bobowk on Mar 2, 2017 19:51:09 GMT 10
ImformasOne last question. How would I add a context menu strip if the 'item' is bookmarked. The problem is I can only declare the 'item' inside a void like this: private void bookmarks_Click(object sender, EventArgs e) { ToolStripItem item = new ToolStripMenuItem(); item.Name = urlTextBox.Text; item.Tag = urlTextBox.Text; Uri Urlh = new Uri( "https://" + new Uri(web.Address).Host + "/favicon.ico"); try { Image Img = new Bitmap(new System.IO.MemoryStream(new WebClient().DownloadData(Urlh))); item.Image = Img; } catch (Exception) { item.Image = Resources.favicons; } item.Font= new Font("Segoe UI", 08); item.Click += (senderObject, eventArgs) => { web.Load(item.Name); }; because if not, it won't add more than one bookmark... So is there a way to add a right click locally?
|
|
Post by Imformas on Mar 3, 2017 2:28:20 GMT 10
Then declare the Item before the click event, then you can reassign it, or create a new instance, or add items to that item. aslong as its not reference NULL ToolStripItem item; private void bookmarks_Click(object sender, EventArgs e) { item = new ToolStripMenuItem(); item.Name = urlTextBox.Text; item.Tag = urlTextBox.Text; Uri Urlh = new Uri( "https://" + new Uri(web.Address).Host + "/favicon.ico"); try { Image Img = new Bitmap(new System.IO.MemoryStream(new WebClient().DownloadData(Urlh))); item.Image = Img; } catch (Exception) { item.Image = Resources.favicons; } item.Font= new Font("Segoe UI", 08); item.Click += (senderObject, eventArgs) => { web.Load(item.Name); };
Programming language'sCSharpC++CObjective-CVBProject'sSharpMediaSharpEditYoutifygithub.com/Stephen-Fox-0
|
|