private void MainWindow_Load(object sender, EventArgs e) { // Setup saveImageDir = Path.Combine(Directory.GetCurrentDirectory(), "images"); if (!Directory.Exists(saveImageDir)) { Directory.CreateDirectory(saveImageDir); } saveArtistsFile = Path.Combine(Directory.GetCurrentDirectory(), "artists"); if (!File.Exists(saveArtistsFile)) { File.Create(saveArtistsFile); } saveAlbumsFile = Path.Combine(Directory.GetCurrentDirectory(), "albums"); if (!File.Exists(saveAlbumsFile)) { File.Create(saveAlbumsFile); } ignoreArtistsFile = Path.Combine(Directory.GetCurrentDirectory(), "ignoreartists"); if (!File.Exists(ignoreArtistsFile)) { File.Create(ignoreArtistsFile); } ignoreAlbumsFile = Path.Combine(Directory.GetCurrentDirectory(), "ignorealbums"); if (!File.Exists(ignoreAlbumsFile)) { File.Create(ignoreAlbumsFile); } // Add panels to panelArray panelArray = new Panel[4]; panelArray.SetValue(this.newPanel, 0); panelArray.SetValue(this.artistPanel, 1); panelArray.SetValue(this.recommendationPanel, 2); panelArray.SetValue(this.settingPanel, 3); showPanel("newPanel"); // load artists artists = File.ReadAllLines(saveArtistsFile); albums = File.ReadAllLines(saveAlbumsFile); Array.Sort(artists, artistCompare); Array.Sort(albums, artistCompare); foreach (string artistName in artists) { artistButton artistButton = new artistButton(); artistButton.artistName = artistName; artistButton.albumCount = 10; // get artist image string currentArtistImage = getArtistImage(artistName); if (!String.IsNullOrEmpty(currentArtistImage)) { artistButton.artistImage = currentArtistImage; } // add the button to the flow layout artistPanel.Controls.Add(artistButton); // check for albums getArtistAlbums(artistName); } /* foreach (string albumName in albums) { albumButton albumButton = new albumButton(); albumButton.artistName = albumName; albumButton.albumCount = 10; // add the button to the flow layout artistPanel.Controls.Add(albumButton); // check for albums getArtistAlbums(albumName); } */ // Add new artist button artistButton newArtistButton = new artistButton(); newArtistButton.AddNewArtistStrings(); newArtistButton.Click += new EventHandler(newArtistButton_Click); // add the button to the flow layout artistPanel.Controls.Add(newArtistButton); }
private void artistTextbox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Console.WriteLine("Keydown: enter"); // create new button and place it before this button in the parent flow layout artistButton artistButt = new artistButton(); artistButt.artistName = artistTextbox.Text; artistButt.albumCount = 10; // add the button to the flow layout if (sender is TextBox) { Console.WriteLine("sender is a textbox"); TextBox buttText = (TextBox)sender; if (buttText.Parent is albumButton) { albumButton butt = (albumButton)buttText.Parent; Console.WriteLine(butt.Parent); if (butt.Parent is FlowLayoutPanel) { Console.WriteLine("Parent is a flowlayoutpanel"); FlowLayoutPanel parentLayout = (FlowLayoutPanel)butt.Parent; parentLayout.Controls.Add(artistButt); } } } } }