字体正在以一种奇怪的方式单独改变——Windows CE

本文关键字:方式单 改变 CE Windows 一种 字体 | 更新日期: 2023-09-27 18:14:01

我有一个Windows-Mobile程序,通过rs232连接重量。

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

字体由大变小

我注意到问题是在第一部分1 -如果我标记这部分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 ?
            }

谁能告诉我为什么和如何解决这个问题?

字体正在以一种奇怪的方式单独改变——Windows CE

在你的代码中试试

 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 { }
            }