如何在WPF表单文本框中显示.cs文件输出? [英] How to display .cs file output in WPF form textbox?

查看:195
本文介绍了如何在WPF表单文本框中显示.cs文件输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.cs文件,显示护照MRZ字段的输出作为输出。我用Textboxes创建了WPF表单。现在我想以WPF形式显示TextBoxes的输出。

怎么做?



我尝试过:



Passport.CS

使用Google.Cloud.Vision.V1; 
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Text.RegularExpressions;
使用System.Threading.Tasks;使用System.Windows
;

命名空间WpfAppFormApp
{
class PassportOcr
{

static string abc;
public void passport()
{
PassportDetailPage pdp = new PassportDetailPage();


Console.WriteLine(--------------------------------- -护照 - - - - - - - - - - - - - - - - - - - - );

string credential_path = @C:\Users\GIS-001 \Downloads\SproutOCR-73c5a7843fb9.json;
System.Environment.SetEnvironmentVariable(GOOGLE_APPLICATION_CREDENTIALS,credential_path);

var client = ImageAnnotatorClient.Create();

var image = Image.FromFile(C:/Users/GIS-001/source/repos/visionapi/visionapi/image/pandimani.jpg);

var response = client.DetectDocumentText(image);




string xyz = response.Text;

xyz = xyz.Replace(,);

string pattern =。*<<。*;
Regex r =新的正则表达式(模式);

foreach(匹配m在r.Matches(xyz))
{
abc + = m.Value;



}

//Console.WriteLine(abc);

// Console.WriteLine(word);

string mrz = abc;
string mrzLines = mrz.Replace(<,);
mrzLines = mrzLines.Trim();

Console.WriteLine(文档类型:+ mrzLines.Substring(0,1).ToString()); // P = Passport
//Console.WriteLine(Type:+ mrzLines.Substring(1,1).ToString());
Console.WriteLine(Document Country:+ mrzLines.Substring(2,3).ToString());
Console.WriteLine(文档所有者:+ mrzLines.Substring(5,39).ToString());

Console.WriteLine(文档编号:+ mrzLines.Substring(44,4).ToString());
//Console.WriteLine(\"Check Digit:+ mrzLines.Substring(54,1).ToString());
Console.WriteLine(国籍:+ mrzLines.Substring(54,3).ToString());
Console.WriteLine(出生日期:+ mrzLines.Substring(57,6).ToString());
//Console.WriteLine(出生日期检查:+ mrzLines.Substring(63,1).ToString());
Console.WriteLine(Sex:+ mrzLines.Substring(64,1).ToString());
Console.WriteLine(文档过期日期:+ mrzLines.Substring(65,6).ToString());
//Console.WriteLine(\"Document Expiry Date Check:+ mrzLines.Substring(71,1).ToString());
//Console.WriteLine (\"Personal Number:+ mrzLines.Substring(72,14).ToString());
//Console.WriteLine (\"Personal Number Check:+ mrzLines.Substring(86,1).ToString());
//Console.WriteLine(完成检查:+ mrzLines.Substring(87,1).ToString());










Console.ReadLine();


}



Passport.xaml

在此文件中我有一个按钮扫描,当我单击此按钮时,它将调用Passport.CS文件并在Passportresult.xaml文本框中显示输出。

解决方案

您的代码有点不清楚。



您需要在表单/窗口上放置文本框,为每个文本框命名,然后选择一种方法来传递或绑定每个文本框的数据。



我将假设您在窗体/窗口代码隐藏中执行此操作:



1. PassportOcr对象

  public   class  PassportOcr 
{
public PassportOcr( string mrzLines)
{
Country = mrzLines .Substring( 2 3 );
Owner = mrzLines.Substring( 5 39 );
Number = mrzLines.Substring( 44 8 );
}

public string 国家{获得; set ; }
public string 所有者{ get ; set ; }
public string Number { get ; set ; }
}



窗口代码隐藏:

  public   partial   class  MainWindow:Window 
{
< span class =code-keyword> public PassportOcr Ocr { get ; set ; }

public SetOcrData( string mrzLines)
{
Ocr = new PassportOcr(mrzLines);

// 向用户显示数据
txtCountry.Text = Ocr.Country;
txtOwner.Text = Ocr.Owner;
txtNumber.Text = Ocr.Number;
}
}



和XAML:

 <  网格 >  
< Grid.RowDefinitions >
< span class =code-keyword>< RowDefinition / >
< RowDefinition / >
< RowDefinition / >
< / Grid.RowDefinitions > ;
< 文本框 x:名称 = txtCountry / >
< 文本框 < span class =code-attribute> x:名称 = txtOwner Grid.Row = 1 / >
< 文本框 x:名称 = txtNumber Grid.Row = 2 / >
< / Grid >


I have a .cs file which displays a output of passport MRZ fields as output. I have created WPF form with Textboxes. Now i want to show that output in WPF form TextBoxes.
How to do that?

What I have tried:

Passport.CS

using Google.Cloud.Vision.V1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;

namespace WpfAppFormApp
{
    class PassportOcr
    {

        static string abc;
        public void passport()
        {
            PassportDetailPage pdp = new PassportDetailPage();
          
           
            Console.WriteLine("----------------------------------PASSPORT----------------------------------------");
           
            string credential_path = @"C:\Users\GIS-001\Downloads\SproutOCR-73c5a7843fb9.json";
            System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

            var client = ImageAnnotatorClient.Create();

            var image = Image.FromFile("C:/Users/GIS-001/source/repos/visionapi/visionapi/image/pandimani.jpg");

            var response = client.DetectDocumentText(image);


           

            string xyz = response.Text;

            xyz = xyz.Replace(" ", "");

            string pattern = ".*<<.*";
            Regex r = new Regex(pattern);

            foreach (Match m in r.Matches(xyz))
            {
                abc += m.Value;



            }

            //Console.WriteLine(abc);

            //    Console.WriteLine(word);

            string mrz = abc;
            string mrzLines = mrz.Replace("<", " ");
            mrzLines = mrzLines.Trim();

            Console.WriteLine("Document Type: " + mrzLines.Substring(0, 1).ToString()); // P=Passport
                                                                                        //Console.WriteLine("Type: " + mrzLines.Substring(1, 1).ToString());
            Console.WriteLine("Document Country: " + mrzLines.Substring(2, 3).ToString());
            Console.WriteLine("Document Owner: " + mrzLines.Substring(5, 39).ToString());
           
            Console.WriteLine("Document Number: " + mrzLines.Substring(44, 8).ToString());
            //Console.WriteLine("Check Digit: " + mrzLines.Substring(54, 1).ToString());
            Console.WriteLine("Nationality: " + mrzLines.Substring(54, 3).ToString());
            Console.WriteLine("Date of birth: " + mrzLines.Substring(57, 6).ToString());
            //Console.WriteLine("Date of birth Check: " + mrzLines.Substring(63, 1).ToString());
            Console.WriteLine("Sex: " + mrzLines.Substring(64, 1).ToString());
            Console.WriteLine("Document Expiry Date: " + mrzLines.Substring(65, 6).ToString());
            //Console.WriteLine("Document Expiry Date Check: " + mrzLines.Substring(71, 1).ToString());
            //Console.WriteLine("Personal Number: " + mrzLines.Substring(72, 14).ToString());
            //Console.WriteLine("Personal Number Check: " + mrzLines.Substring(86, 1).ToString());
            //Console.WriteLine("Complete Check: " + mrzLines.Substring(87, 1).ToString());










            Console.ReadLine();


        }


Passport.xaml
In this file i have a button scan, When i click this button it will call Passport.CS file and display output in Passportresult.xaml textbox.

解决方案

Your code is a little unclear.

You need to put textboxes on the form/window, give each a name, then choose a method to pass or bind the data each textbox.

I will assume that you are doing this in the form/window's code-behind:

1. PassportOcr object

public class PassportOcr 
{
    public PassportOcr(string mrzLines)
    {
        Country = mrzLines.Substring(2, 3);
        Owner = mrzLines.Substring(5, 39);
        Number = mrzLines.Substring(44, 8);
    }

    public string Country { get; set; }
    public string Owner { get; set; }
    public string Number { get; set; }
}


Window code-behind:

public partial class MainWindow : Window
{
    public PassportOcr Ocr { get; set; }

    public SetOcrData(string mrzLines)
    {
        Ocr = new PassportOcr(mrzLines);

        // Show the user the data
        txtCountry.Text = Ocr.Country;
        txtOwner.Text = Ocr.Owner;
        txtNumber.Text = Ocr.Number;
    }
}


And the XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Textbox x:Name="txtCountry" />
    <Textbox x:Name="txtOwner" Grid.Row=1 />
    <Textbox x:Name="txtNumber" Grid.Row=2 />
</Grid>


这篇关于如何在WPF表单文本框中显示.cs文件输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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