如何实现内部foreach按钮单击以确认存储文本框值 [英] How to implement inside foreach button click to conformation to store text box values

查看:55
本文介绍了如何实现内部foreach按钮单击以确认存储文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击按钮值存储在DB中而另一个按钮点击时(跳过)没有chaneges in TextBox值如何调用按钮点击Forloop



添加了代码块 - OriginalGriff [/ edit]



我尝试过:



  foreach (FileInfo info  in  dir.GetFiles (  *。jpg))
{
image_name = info.FullName ;
Image Limg = Image.FromFile(info.FullName);
// MessageBox.Show(image_name);
Image img = new 位图(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
{
位图来源= new 位图(image_name);
Bitmap CroppedImage = source.Clone( new System.Drawing.Rectangle(x,y,width,height),source.PixelFormat);
pictureBox2.Image = new 位图(CroppedImage);

// string Create_dir = @C:\\OCRREAD\\ + Path.GetFileName(fopen.FileName);
// if(!Directory。存在(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( );
// 获取单词的字符
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);

}
}

解决方案

您的代码没有点击按钮 - 它会对用户做出反应当或 foreach 循环正在运行时,用户无法点击按钮 - 或者至少没有具有任何精确度。

如果您想要执行在用户单击按钮时执行的代码,那么这很简单:将代码移动到单独的方法中,并从两者中调用地点:

<前lang =C#> 私人 void MyButton_Click( object sender,EventArgs e)
{
DoMyFunction();
}
private void DoMyFunction()
{
}
...
foreach (FileInfo info in dir.GetFiles( *。jpg))
{
...
DoMyFunction();
...
}



如果您希望用户通过单击按钮确认每个操作,那么这也很简单:只需使用MessageBox:

  foreach (FileInfo info  in  dir.GetFiles(  *。jpg))
{
...
if (MessageBox.Show( 你确定吗? 请确认删除,MessageBoxButtons.YesNo ,MessageBoxIcon.Question)== DialogResult.Yes)
{
...
}
}





如果你想完全做其他事情,那么你需要更详细地解释一下!


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:

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);

                    }
}

解决方案

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:

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:

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!


这篇关于如何实现内部foreach按钮单击以确认存储文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆