0

当从串行端口接收到值时,如何使动态创建的按钮中的特定按钮闪烁并更改其颜色。它应该是这样的:如果从串行端口接收到一个字符,按钮阵列中的一个按钮应该开始闪烁。

4

1 回答 1

1

您可以使用这篇文章 - 基于 SerialPort.DataReceived Event

在实例上创建:

   SerialPort mySerialPort = new SerialPort("..");//Adjust value

    mySerialPort.BaudRate = ...;//Adjust value
    mySerialPort.Parity = Parity.None;
    mySerialPort.StopBits = StopBits.One;
    mySerialPort.DataBits = ..;//Adjust value
    mySerialPort.Handshake = Handshake.None;

    mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

    mySerialPort.Open();

    Console.WriteLine("Press any key to continue...");
    Console.WriteLine();
    Console.ReadKey();
    mySerialPort.Close();

事件 :

 private static void DataReceivedHandler(object sender,  SerialDataReceivedEventArgs e)
 {
        //Change
 }

链接:http: //msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived.aspx

改变颜色:

<input type="button" value="click me" onclick="this.style.color='#000000';
this.style.backgroundColor = '#ffffff'" />

您可以使用此代码 - 基于RegisterClientScriptBlock

      // Get a ClientScriptManager reference from the Page class.
      ClientScriptManager cs = Page.ClientScript;
      StringBuilder cstext2 = new StringBuilder();
      cstext2.Append("<script type=\"text/javascript\">");
      cstext2.Append("document.getElementById("button").bgcolor="#Insert Color Here";</");
      cstext2.Append("script>");
      cs.RegisterClientScriptBlock(.., .., cstext2.ToString(), false);

链接:http: //msdn.microsoft.com/fr-fr/library/vstudio/z9h4dk8y.aspx

于 2012-09-22T10:54:21.947 回答