您的位置:首页 > 其它

鼠标移动到dataGrid单元格,类容全部显示

2008-02-28 13:00 316 查看

using System;


using System.Drawing;


using System.Windows.Forms;




namespace Common




...{


public class ShowAllColumnText




...{


private System.Windows.Forms.DataGrid dg=null;


public ShowAllColumnText(System.Windows.Forms.DataGrid dataGrid)




...{


dg=dataGrid;


}




...#region


bool showAll=true;


public void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)




...{


if(showAll)




...{


Graphics gg=this.dg.CreateGraphics();


TextBox t=(TextBox)sender;


int w=t.Size.Width;


Point p=new Point(t.Location.X,e.Y+t.Location.Y+t.Height);


DrawAllText(((TextBox)sender).Text,w,gg,dg.Font,p);


showAll=false;


}




}


public void MyMouseLeave(object sender, System.EventArgs e)




...{


showAll=true;


dg.Refresh();


}




private void DrawAllText(string text,int w,Graphics g,Font f,Point p)




...{


float h=f.GetHeight();


SizeF sf=g.MeasureString(text,f,w);


int height=(int)sf.Height+5+(int)h;


Size rsf=new Size(w,height);


Rectangle rect= new Rectangle(p,rsf);


RectangleF rectf= new RectangleF(new PointF(p.X,p.Y),new SizeF(rsf.Width,rsf.Height));




g.FillRectangle(Brushes.Gray,rect);


g.DrawRectangle(new Pen(Color.Blue),rect);


rectf= new RectangleF(new PointF(p.X+3,p.Y+3),new SizeF(sf.Width,sf.Height+(int)h));




g.DrawString(" "+text,f,Brushes.Blue,rectf);






}


#endregion


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐