0

我有用于显示来自 GSM 调制解调器的 SMS 的列表视图。我正在读取端口以获取消息,解析它们然后显示它们。我阅读消息时得到的格式是:

+CMGL: 5,"REC READ","IA-612345","","2012/08/04 11:54:00+22"
Some text message

我用来解析的代码:

public ShortMessageCollection ParseMessages(string input)
{
    ShortMessageCollection messages = new ShortMessageCollection();
    Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
    Match m = r.Match(input);
    while (m.Success)
    {
        ShortMessage msg = new ShortMessage();
        msg.Index = m.Groups[1].Value;
        msg.Status = m.Groups[2].Value;
        msg.Sender = m.Groups[3].Value;
        msg.Alphabet = m.Groups[4].Value;
        msg.Sent = m.Groups[5].Value;
        msg.Message = m.Groups[6].Value;
        messages.Add(msg);
        m = m.NextMatch();
    }
}
return messages;

我用来将消息添加到列表视图的循环:

foreach (ShortMessage msg in objShortMessageCollection)
{
    ListViewItem item = new ListViewItem(new string[] { msg.Sender, msg.Message, msg.Sent, msg.Index });
    item.Tag = msg;
    lvwMessages.Items.Insert(0, item);
}

现在我的要求是当我将消息添加到列表视图时,未读的消息(REC UNREAD)应该以粗体显示,而已读的消息应该以普通字体显示。这可能吗?请告诉我程序。

4

1 回答 1

5
if (condition)
{
    item.Font = New Font(item.Font, FontStyle.Bold);
}
于 2012-08-08T11:56:48.877 回答