C#C
C#3y ago
Hiccup

❔ Create a picturebox_clicked event for each picturebox created

private Form1 form1 { get; set; }
    readonly HttpClient httpClient = new();
    public static string FolderPath = @".\Storage";
    public static int picNum = 0;
    public static List<string> outofScopeURL = new List<string>();
    
    private async void Detailed_View_Load_1(object sender, EventArgs e)
    {
        DirectoryInfo directory = new(FolderPath);
        FileInfo[] files = directory.GetFiles();
        string[] FileFormats = { ".png", ".jpg", ".jpeg", ".txt" };
        for (int pictureCreator = 0; pictureCreator < files.Length; pictureCreator++)
        {
            FileInfo file = files[pictureCreator];
            if (file.FullName.EndsWith(FileFormats[3])) 
            {
                string url = File.ReadAllText(file.FullName);
                if (url != null)
                {
                    try
                    {
                        Image gif = Image.FromStream(await httpClient.GetStreamAsync(url));
                        PictureBox picture = new PictureBox
                        {
                            Name = url,
                            Size = new(38, 38),
                            Image = gif,
                            Location = new((gif.Width * pictureCreator), 0),
                            SizeMode = PictureBoxSizeMode.Zoom
                        };
                        this.Controls.Add(picture);
                        MessageBox.Show(picture.Name);
                        outofScopeURL.Add(url);
                        picture.Click += Picture_Click;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                picNum++;
            }
        }
    }
Was this page helpful?