C#中的可见属性 [英] Visible property in C#

查看:100
本文介绍了C#中的可见属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,使用串口从串口接收数据,然后根据它添加一些按钮。我已经在文本框中显示了所有收到的数据,我现在要做的就是:如果收到的字符串包含0x0000,它将隐藏一个按钮和一个文本框,这是我到目前为止所尝试的:



I'm writing a programm using serial port to receive data from serial port, then based on it to add some buttons. I've already shown all the received datas in a textbox,and all I want to do now is : If in the received string contains "0x0000", it will hide a button and a textbox, here's what i 've tried so far:


if (myString.Contains("0x0000"))
{
    newtemperature.Visible = false;
    neue_temperatur.Visible = false;
}







仅当字符串0x0000是最后一个字符串时才有效接收。然后我尝试了Enabled属性,它完美无缺!但我还是想隐藏那些按钮。我怎么能这样做?任何帮助表示赞赏!




It works only, when the string "0x0000" was the last string received. Then i tried the Enabled property, it works perfectly! But I still want to hide those buttons.How could i do this? Any help is appreciated!

推荐答案


public delegate void AddDataDelegate(String myString);

public AddDataDelegate myDelegate;



void scanOnOff()

{

serialPort1 .DataReceived + = new SerialDataReceivedEventHandler(serialPort1_DataReceived);

myDelegate = AddDataMethod;

}



void serialPort1_DataReceived(对象发送者,SerialDataReceivedEventArgs e)

{

SerialPort port =(SerialPort)sender;

string indata = port.ReadLine();

Console.WriteLine(indata);

richTextBox1.Invoke(myDelegate,new Object [] {indata});

}



public void AddDataMethod(String myString)

{

if(myString.Contains(0x0000))

{

newtemperature.Visible = false;

neue_temperatur.Visible = false;

}

}

public delegate void AddDataDelegate(String myString);
public AddDataDelegate myDelegate;

void scanOnOff()
{
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
myDelegate = AddDataMethod;
}

void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;
string indata = port.ReadLine();
Console.WriteLine(indata);
richTextBox1.Invoke(myDelegate, new Object[] { indata });
}

public void AddDataMethod(String myString)
{
if (myString.Contains("0x0000"))
{
newtemperature.Visible = false;
neue_temperatur.Visible = false;
}
}


请你发表完整的代码吗?

我不知道在你的代码中看到任何错误,如果mySring包含0x0000,那么隐藏一些控件。



你还提到它只有在最后收到的字符串时才有效是0x0000。您能否检查一下,在一个变量中连接您收到的所有字符串,然后对该单个变量应用该检查?
Can you please Post the complete code?
I do not see anything wrong in your code as its very straight forward that if mySring contains 0x0000, then hide some controls.

Also you mentioned that it works only if the last received string is 0x0000. Can you please check, to concatenate all the string which you are receiving in a single variable and then apply that check on that single variable?


这篇关于C#中的可见属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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