Isn't it possible to create the name associated to the _Click
action while the button hasn't been created in beforehand? It's a little hard to explain but I think it gets clearer while skimming through my code:
index = Array.FindIndex(bookmarks, i => i == null || i.Length == 0); //find closest empty spot in array
bookmarks[index] = "http://" + Urlbox.Text;
book[index] = new Button();
book[index].Height = 31;
book[index].Content = bookmarks[index];
book[index].Click += book[index]_Click;
Bookbar.Items.Add(book[index]);
My method as follows:
public void book[index]_Click(object sender, RoutedEventArgs e)
{
WebBrowser1.Navigate("random url");
}
As you can see, my button is programmatically created before I try to add an action to it. However, I'm getting the wierd error Error 1 ; expected
under the line creating my action. Although, changing that line to book[index].Click += Bookmark_Click;
where Bookmark
is in beforehand an existing button seems to work just fine.
The reason im using arrays is that I want to create multiple buttons and give each one of them a different _Click
action. What am I doing wrong?