CodeAs follows:
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using system. Data. sqlclient;
Namespace exam2
{
Public partial class mainform: Form
{
Private int cellcolumnindex =-1; // column Index
Private int cellrowindex =-1; // row Index
Public mainform ()
{
Initializecomponent ();
// Set the property value of the prompt Tool
This. dgvuserinfo. showcelltooltips = false;
This. tooltip. automaticdelay = 0;
This. tooltip. ownerdraw = true;
This. tooltip. showalways = true;
This. tooltip. tooltiptitle = "";
This. tooltip. useanimation = true;
This. tooltip. usefading = true;
}
/// <Summary>
/// Display User Information
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void mainform_load (Object sender, eventargs E)
{
String SQL = "Select User ID = userid, user name = Name, user name = username, User Password = userpassword from userinfo ";
Sqlconnection conn = dbhelper. getconnection ();
Sqldataadapter adapter = new sqldataadapter (SQL, Conn );
Dataset DS = new dataset ();
Adapter. Fill (DS );
This. dgvuserinfo. datasource = Ds. Tables [0];
}
private void dgvuserinfo_cellmouseleave (Object sender, datagridviewcelleventargs e)
{< br> This. tooltip. hide (this. dgvuserinfo); // hide the prompt tool after removing the mouse from the cell
}
Private void dgvuserinfo_cellmouseenter (Object sender, datagridviewcelleventargs E)
{
// Determine the validity of the selected cell
If (E. rowindex <0 | E. columnindex <0)
{
Return;
}
This. tooltip. Hide (this. dgvuserinfo );
This. cellcolumnindex = E. columnindex; // obtain the column Index
This. cellrowindex = E. rowindex; // obtain the row index.
If (this. cellcolumnindex> = 0 & this. cellrowindex> = 0)
{
Point mousepos = pointtoclient (mouseposition); // obtain the current mouse position
// Obtain the value of the cell to which the mouse is moved
String tip = This. dgvuserinfo [This. cellcolumnindex, this. cellrowindex]. value. tostring ();
This. tooltip. Show (TIP, this. dgvuserinfo, mousepos); // display the prompt tool at the specified position
}
}
// drawing prompt tool
private void tooltip_draw (Object sender, drawtooltipeventargs e)
{< br> E. graphics. fillrectangle (brushes. aliceblue, E. bounds);
E. graphics. drawrectangle (pens. chocolate, new rectangle (0, 0, E. bounds. width-1, E. bounds. height-1);
E. graphics. drawstring (this. tooltip. tooltiptitle + E. tooltiptext, E. font, brushes. red, E. bounds);
}< BR >}