By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,571 Members | 2,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,571 IT Pros & Developers. It's quick & easy.

drawing my own control - slow at runtime

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
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?

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
"Benoit Martin" <bm*********@hotmail.com> scripsit:
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?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a
"Benoit Martin" <bm*********@hotmail.com> scripsit:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
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

"Benoit Martin" <bm*********@hotmail.com> wrote in message
news:uH***************@tk2msftngp13.phx.gbl...
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.

Nov 20 '05 #7

P: n/a
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
"Benoit Martin" <bm*********@hotmail.com> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
: 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.
:
:
Nov 20 '05 #8

P: n/a
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

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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
"Benoit Martin" <bm*********@hotmail.com> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
: 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.
:
:

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.