drawing my own control - slow at runtime

  • Thread starter Thread starter Benoit Martin
  • Start date Start date
B

Benoit Martin

I had to draw my own control because I couldn't find any control doing what
I wanted it to do. This control has a grid that I need to have control over.
To do that, I draw each line of the grid using a 1pixel pictureBox. I also
need "boxes" to be placed within that grid depending on data pulled from my
dataset. I also used pictureBox controls for that. All those components that
I use to draw my control are added to the controls collection of the parent
control. The problem is that when I do a myControl.controls.clear() to clear
the control before I redraw it, I can see each line and each box being
deleted one by one and that happens pretty slowly. I didn't have a chance to
test on other computers but the computer I'm using is decent (1Ghz with
512Mb of RAM).

Am I having the wrong approach to solve my problems or is there something I
can do to speed up the clear method?

Thanks

B.
 
Hi Benoit,

At a guess I'd say wrong approach. ;-)

I don't understand what you are doing, but "draw each line of the grid
using a 1pixel pictureBox" makes me wince!!

Have you thought about actually <drawing> your lines and boxes using the
Draw functions of the Graphics object?

Regards,
Fergus
 
oops, I guess that my inexperience with .net shows here :)

Are lines created with the Draw function considered as components or
objects? Can I add them to a collection of controls so that they belong to a
control?
 
Hi Benoit,

What control are you using for your grid?

The lines that you draw are just lines of pixels. They aren't controls or
objects. They don't exist except as pixels in a bitmap. And even then, they
will get wiped out and have to be redrawn when yourever form gets covered and
uncovered.

Typically, if you are drawing your own control, you write code to handle
the Paint event. This event supplies a Graphics object which you can use to do
your drawing with. There are a lot of drawing functions - to do lines,
circles, ellipses, rectangles, text in various flavours. There are also
functions which will do the drawing of various controls, like buttons,
checkboxes, etc, etc.

What exactly are you trying to achieve? And what's wrong with the
available controls?

Regards,
Fergus
 
Benoit Martin said:
I had to draw my own control because I couldn't find any control doing what
I wanted it to do. This control has a grid that I need to have control over.
To do that, I draw each line of the grid using a 1pixel pictureBox. I also
need "boxes" to be placed within that grid depending on data pulled from my
dataset. I also used pictureBox controls for that. All those components that
I use to draw my control are added to the controls collection of the parent
control. The problem is that when I do a myControl.controls.clear() to clear
the control before I redraw it, I can see each line and each box being
deleted one by one and that happens pretty slowly. I didn't have a chance to
test on other computers but the computer I'm using is decent (1Ghz with
512Mb of RAM).

You will have to create virtual controls on the control. Remove the
pictureboxes and draw the data (grid, etc.) directly onto the form.
Then you check in the appropriate events if the user clicks a cell and
position a single textbox which is instantiated on the control on this cell.
 
Benoit Martin said:
Are lines created with the Draw function considered as components or
objects? Can I add them to a collection of controls so that they belong to a
control?

Do you draw the lines directly onto the control or du you use
pictureboxes?
 
Benoit,
In addition to the Fergus's & Herfried's comments about doing the drawing
yourself with the Graphics object (in the Paint event OnPaint override).

The microsoft.public.dotnet.framework.drawing newsgroups provides assistance
dedicated to Graphics & drawing.

Charles Petzold's book "Programming Microsoft Windows with Microsoft Visual
Basic .NET" from MS press provides a wealth of information on using the
Graphics object in .NET.

The following articles discusses how to create a .NET Line control that
wraps Win32 STATIC controls. useful for lines in dialog boxes (not grids per
se).
http://www.codeproject.com/cs/miscctrl/hvrules1.asp

Hope this helps
Jay
 
In addition to everyone's comments, drawing a grid can be accomplished if
you take a look at the ControlPaint class, I believe it contains a method
that allows you to perform Grid-Painting.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations


: I had to draw my own control because I couldn't find any control doing
what
: I wanted it to do. This control has a grid that I need to have control
over.
: To do that, I draw each line of the grid using a 1pixel pictureBox. I also
: need "boxes" to be placed within that grid depending on data pulled from
my
: dataset. I also used pictureBox controls for that. All those components
that
: I use to draw my control are added to the controls collection of the
parent
: control. The problem is that when I do a myControl.controls.clear() to
clear
: the control before I redraw it, I can see each line and each box being
: deleted one by one and that happens pretty slowly. I didn't have a chance
to
: test on other computers but the computer I'm using is decent (1Ghz with
: 512Mb of RAM).
:
: Am I having the wrong approach to solve my problems or is there something
I
: can do to speed up the clear method?
:
: Thanks
:
: B.
:
:
 
Tom,
I was going to mention ControlPain.DrawGrid in my post, however I did not as
it draws a grid of dots, not a grid of lines.

It really depends on the kind of grid that Benoit wants. Benoit mention
lines, so I assumed he did not want a grid of dots.

Just a thought
Jay
 
Back
Top