Listview以粗体显示未读消息,以C#中的普通字体显示读取消息

时间:2012-08-08 11:54:31

标签: c# winforms listview modem bold

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

+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);
}

现在我的要求是当我向listview添加消息时,未读取的消息(REC UNREAD)应以粗体字体显示,而消息READ应以普通字体显示。这可能吗?请让我知道这个程序。

1 个答案:

答案 0 :(得分:5)

if (condition)
{
    item.Font = New Font(item.Font, FontStyle.Bold);
}