C# winfrom窗体编程,要更改listview的字体大小和颜色,自定义一个识配器,可重复用于修改listview这些元素,例子如下:

private class MyAdapter extends BaseAdapter{         
        @Override       
         public int getCount()
        {
                 return strArr.length;
         }
         @Override
        public Object getItem(int arg0) {
             return arg0;
         }
         @Override
         public long getItemId(int position) {
             return position;
         }
         @Override
         public View getView(int position,View convertView,ViewGroup parent)             {
            // position就是位置从0开始,convertView是Spinner,ListView中每一项要显示的view
            // 通常return 的view也就是convertView
            // parent就是父窗体了,也就是Spinner,ListView,GridView了.
            TextView mTextView = new TextView(getApplicationContext());
             SharedPreferences preferences = getSharedPreferences("PeiZhi_WenJian", Context.MODE_PRIVATE);
             
        mTextView.setTextColor(Color.BLACK);//设置字体颜色(black为黑色)
        mTextView.setTextSize(20);//设置字体大小
        mTextView.setText(strArr[position]);//需要重新添加字体
        return mTextView;
         }
}

在需要修改listview文字颜色的地方调用一下这个方法就可以:

listview.MyAdapter();
List<ReceivableDetail> list = manager.GetList(Ids,CheckedValue);
for (int i = 0; i < list.Count; i++)
{
ListViewItem item = new ListViewItem(list[i].Id.ToString());
item.Tag = list[i];
item.SubItems.Add(list[i].ReceivableId.ToString());
item.SubItems.Add(list[i].OrderId.ToString());
item.SubItems.Add(list[i].SourceFileName.ToString());
item.SubItems.Add(list[i].OrderPrice.ToString());
item.SubItems.Add(list[i].PrintingCount.ToString());
item.SubItems.Add(list[i].Machining.ToString());
item.SubItems.Add(list[i].MachiningPrice.ToString());
item.SubItems.Add(list[i].DiscountPrice.ToString());
item.SubItems.Add(list[i].DiscountUser.ToString());
item.SubItems.Add(list[i].DiscountReason.ToString());

item.SubItems.Add(list[i].ChangPriceBefore.ToString());
item.SubItems.Add(list[i].ChangPriceUser.ToString());
item.SubItems.Add(list[i].SubtotalPrice.ToString());

lvReceD.Items.Add(item);
//设置指定列的字体颜色为红色
lvReceD.Items[i].UseItemStyleForSubItems = false;
lvReceD.Items[i].SubItems[7].ForeColor = Color.Red;
lvReceD.Items[i].SubItems[13].ForeColor = Color.Red;

}