How to show picturebox image in c# according to the individual digit of roll no?

问题内容:

I have a roll no of 6 digits. Below every digit there are 10 images(picturebox). WHen any digit matches with the last value of picturebox like 0 I want to show that image and hides other. Here is my code:

private void btnFill_Click(object sender, EventArgs e)
    {

        string[] splitted = System.Text.RegularExpressions.Regex.Split(rollNo, @"\s{2,}");
        int[] nums = new int[splitted.Length];
        int index1, index2, index3, index4, index5,index6;
        index1 = index2 = index3 = index4 = index5 = index6 = 0;
        for (int i = 0; i < splitted.Length; i++)
        {
            if (splitted != null || splitted.Length != 0)
            {
                nums[i] = int.Parse(splitted[i]);                                
            }
        }
        for (int i = 0; i < nums.Length; i++)
        {
            index1 = nums[0];
            index2 = nums[1];
            index3 = nums[2];
            index4 = nums[3];
            index5 = nums[4];
            index6 = nums[5];
        }

        ////spliting pictyureBoxes
        string[] pic0 = pictureBox0.Name.Split(new String[] {"pictureBox"}, 
StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i< pic0.Length; i++)
        {
            MessageBox.Show(pic0.ToString());


        foreach (PictureBox[] item in Controls.)
        {

        }

    }

问题评论:

    
What does your code do now? What do you want it to do instead?

答案:

答案1:

If I`m rightly understanding, you need something so.
You can place under every digit a picture box. And by clicking on the button or by changing the digit you can change the source of PictureBox by its property Image

答案评论:

    
yES S. Vladimir your are right but there should be 10 images under every digit and based upon digit I want to show that image
– waqasqureshi
4 hours ago
    
But for what you need to place 10 images under every digit if you want to show only one? For this purpose I suggest you to change only Source of PictureBox.
    
I think it will be easier than placing 10 images under every digit and hide/show them
    
yes please show code for only one image
– waqasqureshi
3 hours ago
    
Try pictureBox1.Image = Image.FromFile(path);

原文地址:

https://stackoverflow.com/questions/47752188/how-to-show-picturebox-image-in-c-sharp-according-to-the-individual-digit-of-rol

Tags:,

添加评论