获取字符串像素长度

最近搞mobile windows开发,遇到要测算字符串和宽度,以前没怎么注意过,用起来还真不知道怎么搞,现把方法记录下来:
代码
try
                {
                    Graphics g 
= Graphics.FromImage(imageList1.Images[0]);// FromHdc(this.Handle);
//获取listview控件中的字体
                    Font myf = lvdetail.Font;
                                        SizeF size0 
= g.MeasureString(str0, myf);
设置其宽度
                    lvdetail.Columns[
1].Width = (int)size0.Width ;
                                   }
                
catch (Exception)
                {
                    MsgManager.NormalMsg(
"0011");
                    
return;
                }

 

posted @ 2010-03-04 14:51  古史漫谈  阅读(618)  评论(0)    收藏  举报