Groups | Blog | Home
all groups > vb.net > march 2005 >

vb.net : DataGrid OnPaint/? -How Do I Draw A GDI Type Circle On Top Of A DataGrid


Richard
3/26/2005 10:33:58 PM
I want to put a GDI type circle on top of my DataGrid (actually I want =
to put GDI colored border around the entire selected row, but if I can =
figure out how to put a circle on top of it I can do the border)=20

=20

My main form uses a MyDataGrid. instance as the folowing code from =
MyDataGrid.cs

=20

public class MyDataGrid : DataGrid

..

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

}

=20

On my small datagrid it hits this code about a 100 or so times, it seems =
it's painting each cell, headers, etc individually with all that =
TableStyles stuff.

=20

Where in my code would I do the circle painting thing. Or, where in my =
code am I after it finishes with this OnPaint. Is this done in my main =
form, or do I need to do it somewhere in MyDataGrid.cs that it hits =
after it's done with the OnPaint?

=20

Bob Powell [MVP]
3/27/2005 2:43:07 PM
I would suggest that this could best be accomplished using the =
LayeredWindow API in a NativeWindow derived class. Drawing directly onto =
the desktop is possible but has refresh problems. A NativeWindow could =
be made a child of the DataGrid window and therefore clip to the area of =
the datagrid automatically.

--=20
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.=20
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
I want to put a GDI type circle on top of my DataGrid (actually I want =
to put GDI colored border around the entire selected row, but if I can =
figure out how to put a circle on top of it I can do the border)=20

=20

My main form uses a MyDataGrid. instance as the folowing code from =
MyDataGrid.cs

=20

public class MyDataGrid : DataGrid

.

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

}

=20

On my small datagrid it hits this code about a 100 or so times, it =
seems it's painting each cell, headers, etc individually with all that =
TableStyles stuff.

=20

Where in my code would I do the circle painting thing. Or, where in my =
code am I after it finishes with this OnPaint. Is this done in my main =
form, or do I need to do it somewhere in MyDataGrid.cs that it hits =
after it's done with the OnPaint?

=20

Richard
3/27/2005 2:52:21 PM
I was able to subclass the DataGrid and override the OnPaint. It drew a =
nice GDI border around a row. I hard coded it. I'm sure there are a =
myriad of potential show stoppers with this method. One is I hope I'll =
be able to figure a way to put the border on the right place on the =
screen over the DataGrid for the selected row. I'll have to probably =
somehow get the number of pixels on the drawing area down from the top =
of the visible x,y of the datagrid control, etc.?

Any pointers (no pun intended)?

protected override void OnPaint(PaintEventArgs pe)=20
{
base.OnPaint(pe);
// Create pen.=20
Pen blackPen =3D new Pen(Color.Green, 2);
// Create location and size of rectangle.
float x =3D 15.0F;
float y =3D 53.0F;
float width =3D 500.0F;
float height =3D 20.0F;
}
pe.Graphics.DrawRectangle(blackPen, x, y, width, height);

[quoted text, click to view]
I would suggest that this could best be accomplished using the =
LayeredWindow API in a NativeWindow derived class. Drawing directly onto =
the desktop is possible but has refresh problems. A NativeWindow could =
be made a child of the DataGrid window and therefore clip to the area of =
the datagrid automatically.

--=20
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.=20
Subscribe to the RSS feeds provided and never miss a new article.




=20
[quoted text, click to view]
I want to put a GDI type circle on top of my DataGrid (actually I =
want to put GDI colored border around the entire selected row, but if I =
can figure out how to put a circle on top of it I can do the border)=20

=20

My main form uses a MyDataGrid. instance as the folowing code from =
MyDataGrid.cs

=20

public class MyDataGrid : DataGrid

.

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

}

=20

On my small datagrid it hits this code about a 100 or so times, it =
seems it's painting each cell, headers, etc individually with all that =
TableStyles stuff.

=20

Where in my code would I do the circle painting thing. Or, where in =
my code am I after it finishes with this OnPaint. Is this done in my =
main form, or do I need to do it somewhere in MyDataGrid.cs that it hits =
after it's done with the OnPaint?

=20

AddThis Social Bookmark Button