【问题标题】:fonts are Changing alone in a strange way - Windows CE字体以一种奇怪的方式单独变化 - Windows CE
【发布时间】:2015-09-21 20:03:50
【问题描述】:

我有通过 rs232 连接重量的 Windows-Mobile 程序。

它的工作非常好,但是如果程序在一段时间内工作 -

字体是单独从大字体变为小字体

我注意到问题出在第一部分 - 如果我标记这部分 1

字体不会改变。 (我不知道为什么会这样……)

我的代码:

//PART 1

    port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One); 
    port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Recepcion);

     private SerialPort port;
            StringBuilder SB;
            private void Recepcion(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                try
                {
                    SB = new StringBuilder(1000);
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(122);
                    SB.Append(port.ReadExisting());
                    port.DiscardInBuffer();
                    this.Invoke(new EventHandler(Actualizar));
                }
                catch { }
            }


    //PART2
            string MOMO1, MOMO2;
            string[] WI;
            string ALL;
            private void Actualizar(object s, EventArgs e)
            {
                ALL = SB.ToString().Trim();
                WI = ALL.Split(',');
                ALL = WI[2].ToString().Trim();
                MOMO1 = ALL.Replace("+", "").Replace("g", "").Replace("ST", "").Replace("GS", "").Replace("US", "");
                if (MOMO1 != "")
                {
                    MOMO2 = MOMO1;
                }
                lblMSG.Font = new Font("Ariel", 48, FontStyle.Bold);
                lblMSG.Text = MOMO2;
                Check_Weight();
                GC.Collect();  // <-- is it OK ?
            }

谁能告诉我为什么以及如何解决它?

【问题讨论】:

  • Check_Weight() 中发生了什么?
  • 嗨,在 Check_Weight() 中 - 非常简单的方法 - 没有意义
  • 嗨,我更新了我的问题。

标签: c# serial-port windows-mobile windows-ce


【解决方案1】:

在你的代码中试试这个

 private SerialPort port;
            StringBuilder SB;
            private void Recepcion(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                try
                {
                    SB = new StringBuilder(1000);
                    SB.Append(port.ReadLine());
                    port.DiscardInBuffer();
                    this.Invoke(new EventHandler(Actualizar));
                }
                catch { }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    相关资源
    最近更新 更多