Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从文本框中提取数字_C#_Textbox_Picturebox - Fatal编程技术网

C# 从文本框中提取数字

C# 从文本框中提取数字,c#,textbox,picturebox,C#,Textbox,Picturebox,我必须为学校做一个程序,一个D触发器。要输入D和e/时钟,我需要使用两个文本框。我还必须制作一个包含AND、NAND、OR、NOR、XOR端口的3个端口的程序,但已经可以工作了 D的输入可以是:0000011111 0000011111 00000011 E的输入可以是:000110001110001110001111000111 textbox1中的值必须转到picturebox。因此,使用0和1可以画一条线,使触发器可见。textbox2中的值需要转到picturebox2。这是可能的。实际

我必须为学校做一个程序,一个D触发器。要输入D和e/时钟,我需要使用两个文本框。我还必须制作一个包含AND、NAND、OR、NOR、XOR端口的3个端口的程序,但已经可以工作了

D的输入可以是:0000011111 0000011111 00000011

E的输入可以是:000110001110001110001111000111


textbox1中的值必须转到picturebox。因此,使用0和1可以画一条线,使触发器可见。textbox2中的值需要转到picturebox2。

这是可能的。实际上,您需要将0000011111 00000111111100000111或00011000111000111100011110001111000111转换为字节数组字节[]。为此,我们将使用Convert.ToByteobject值,即IFormatProvider

最后,我们可以简单地使用该流创建图像文件,并将该文件设置为PictureBox

范例

重要提示:您可能会收到ArgumentException未处理:参数无效。这可能是由于无效的二进制代码造成的

谢谢,
我希望这对您有所帮助:

myTextbox.Text?我需要在你的问题中看到一些代码!听起来你最好开始写一些代码。。。如果这是一项学校作业,如果您不了解基本的编码,让我们为您编码将不会对您有任何好处。。如果讲师问你如何得出答案/解决方案,该怎么办。。?那你会看起来像一头戴着头灯的鹿。。!您描述了一个项目,但没有提出任何问题,您是否在从文本框中读取文本、在图片框中绘制文本、绘制线条、计算结果、绘制结果方面存在问题。哪一部分让你烦恼?我现在只有textBox1_按键。e、 已处理=\b01.Containse.KeyChar;因此,文本框中只有0 en 1。因此,文本框的值包含一行0和1。我想把每一个数字都换成一个新的整数,这样我就可以用0或1来告诉图片Box1如何画一条线。但是我想我最好现在停下来,第二天早上重新开始haha@user1786774根据我从您的问题中了解到的情况,您希望从字节[]中读取图像。然后,将图像链接到PictureBox。不是吗?如果我错了,请纠正我。祝你有美好的一天:
string input = "BINARY GOES HERE";
int numOfBytes = input.Length / 8; //Get binary length and divide it by 8
byte[] bytes = new byte[numOfBytes]; //Limit the array
for (int i = 0; i < numOfBytes; ++i)
{
     bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2); //Get every EIGHT numbers and convert to a specific byte index. This is how binary is converted :)
}
MemoryStream FromBytes = new MemoryStream(bytes); //Create a new stream with a buffer (bytes)
pictureBox1.Image = Image.FromStream(FromBytes); //Set the image of pictureBox1 from our stream
private Image Decode(string binary)
{
    string input = binary;
    int numOfBytes = input.Length / 8;
    byte[] bytes = new byte[numOfBytes];
    for (int i = 0; i < numOfBytes; ++i)
    {
        bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2);
    }
    MemoryStream FromBinary = new MemoryStream(bytes);
    return Image.FromStream(FromBinary);
}
pictureBox1.Image = Decode("000001111100000111111100000011");