Click here to Skip to main content
16,012,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when user click on button values are stored in DB and another Button clicked that like (skip) no chaneges in TextBox values how to call button click in Forloop

[edit]Code block added - OriginalGriff[/edit]

What I have tried:

C#
foreach (FileInfo info in dir.GetFiles("*.jpg"))
                {
                    image_name = info.FullName;
                    Image Limg = Image.FromFile(info.FullName);
                   // MessageBox.Show(image_name);
                    Image img = new Bitmap(Limg, 700, 580);
                    pictureBox1.Image = img;
                    //getfile = fopen.FileName;
                    Application.DoEvents();
                    //System.Threading.Thread.Sleep(1000);
                    x = 1200;
                    int y = 430, width = 230, height = 80;
                    if (x == 1200)
                    {
                        Bitmap source = new Bitmap(image_name);
                        Bitmap CroppedImage = source.Clone(new System.Drawing.Rectangle(x, y, width, height), source.PixelFormat);
                        pictureBox2.Image = new Bitmap(CroppedImage);

                        //string Create_dir = @"C:\\OCRREAD\\"+ Path.GetFileName(fopen.FileName);
                        //if (!Directory.Exists(Create_dir))
                        //{
                        // Directory.CreateDirectory(Create_dir);
                        CroppedImage.Save(@"C:\\OCRREAD\\" + info);
                        getfile = @"C:\\OCRREAD\\" + info;
                        // }
                        Application.DoEvents();
                        MODI.Document objModi = new MODI.Document();
                        objModi.Create(getfile);
                        objModi.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                        MODI.Image image = (MODI.Image)objModi.Images[0];
                        MODI.Layout layout = image.Layout;
                        StringBuilder sb = new StringBuilder();
                        for (int j = 0; j < layout.Words.Count; j++)
                        {
                            MODI.Word word = (MODI.Word)layout.Words[j];
                            sb.Append(word.Text);
                            sb.Append(" ");
                            // getting the word's characters
                            for (int k = 0; k < word.Rects.Count; k++)
                            {
                                MODI.MiRect rect = (MODI.MiRect)word.Rects[k];
                                charactersHeights += rect.Bottom - rect.Top;
                                numOfCharacters++;
                            }
                        }
                        File.Delete(getfile);
                        Firstvalue = sb.ToString();
                        if (Firstvalue.Contains("-"))
                        {
                            Firstvalue = Firstvalue.Replace("-", "");
                        }
                        //MessageBox.Show(Firstvalue);

                    }
}
Posted
Updated 16-Jul-16 3:11am
v2

1 solution

Your code doesn't "click" buttons - it reacts to what the user does, and the user can't click a button while a for or foreach loop is running - or at least not with any precision.
If you mean that you want to execute the code that would be executed when the user clicks a button, then that's simple: move the code into a separate method, and call that from both places:
C#
private void MyButton_Click(object sender, EventArgs e)
    {
    DoMyFunction();
    }
private void DoMyFunction()
    {
    }
    ...
    foreach (FileInfo info in dir.GetFiles("*.jpg"))
        {
        ...
        DoMyFunction();
        ...
        }

If you mean that you want the user to confirm each action by clicking a button, then that's simple as well: just use MessageBox:
C#
foreach (FileInfo info in dir.GetFiles("*.jpg"))
    {
    ...
    if (MessageBox.Show("Are you sure?", "Please confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
        {
        ...
        }
    }


If you are trying to do something else entirely, then you need to explain in a lot more detail!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900