C#XML阅读器文本到文本框无法复制。 [英] C# XML reader text to textbox can not be copied.

查看:93
本文介绍了C#XML阅读器文本到文本框无法复制。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try
                {
                Application.DoEvents();
                string uri = "https://pastebin.com/raw/ZYGRDhk0";
                XDocument document = XDocument.Load(uri);
                System.Xml.XmlTextReader reader = new XmlTextReader(uri);
                XmlNodeType type;
                Application.DoEvents();
                while (reader.Read())
                    {
                    type = reader.NodeType;

                    if (type == XmlNodeType.Element)
                        {
                       
                        if (reader.Name == "Code1")
                            {
                            reader.Read();
                            Application.DoEvents();
                            code1.Text = (reader.Value);

                            }
                        if (reader.Name == "Code2")
                            {
                            reader.Read();
                            Application.DoEvents();
                            code2.Text = (reader.Value);


                            }
                        if (reader.Name == "ImagemCode1")
                            {
                            reader.Read();
                            Application.DoEvents();
                            Imagecode1 = (reader.Value);
                            }


                       

                        }
                        }

                    

                reader.Close();
               
                }
            catch { }
            finally
                {
                if (code1.Text.Contains("Code"))
                    {
                    button13.Visible = false;

                    }
                }
            }





我尝试过:





What I have tried:

code1.Text = (reader.Value);



问题是,当我从文本框中复制文本时,code1.Text没有复制任何内容。无法复制。我是否需要以不同的方式进行读取?

就像文本在沙箱中一样。他是我复制的那个,但它没有复制。


The problem is that when I copy the text from the textbox code1.Text nothing was copied. Can not copy. Do I need to do the read differently?
It's as if the text is in a sandbox. He is the one I copy but it does not copy.

推荐答案

如果你正在使用 Application.DoEvents()


关于这段你还没有告诉我们的代码,比如它是从另一个线程运行,还是什么?



你的catch块也是空的,这意味着这个代码抛出的任何异常都会被吞噬,使得调试过程变得更加困难。



您的代码看起来很混乱,就像您创建一个XDocument对象,但从不使用它。



我们也不知道您的XML文件是什么看起来如果它甚至被阅读。摆脱Try / Catch的东西和所有的Application.DoEvents并再试一次。



如果它仍然失败,这就是调试器派上用场的地方所以你可以检查变量,以便在代码运行时逐行查看其中的内容。
If you're using Application.DoEvents(), you're doing something very wrong.

There's something about this code you haven't told us, like is it running from another thread, or what?

Your catch block is also empty, which means any exceptions this code throws will get swallowed, making the debugging process much more difficult.

Your code looks confused, like you create an XDocument object, but never use it.

We also have no idea what your XML file looks like, of if it's even being read. get rid of the Try/Catch stuff and all the Application.DoEvents and try it again.

If it still fails, this is where the debugger comes in handy so you can inspect variables to see what's in them as the code runs, line by line.


已解决。 xml中断行​​中的错误会在texbox.text上出错。


这篇关于C#XML阅读器文本到文本框无法复制。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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