PC Review


Reply
Thread Tools Rate Thread

drawing my own control - slow at runtime

 
 
Benoit Martin
Guest
Posts: n/a
 
      4th Oct 2003
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.


 
Reply With Quote
 
 
 
 
Fergus Cooney
Guest
Posts: n/a
 
      4th Oct 2003
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


 
Reply With Quote
 
Benoit Martin
Guest
Posts: n/a
 
      4th Oct 2003
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" <filter-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      4th Oct 2003
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


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Oct 2003
"Benoit Martin" <(E-Mail Removed)> 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>
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Oct 2003
"Benoit Martin" <(E-Mail Removed)> 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>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      4th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:uHq%(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      5th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:uHq#(E-Mail Removed)...
: 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.
:
:


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      5th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:%23$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:uHq#(E-Mail Removed)...
> : 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.
> :
> :
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
drawing on an inserted image at runtime ? Asking Microsoft C# .NET 0 20th Jun 2007 07:25 PM
Slow Graphics Drawing with GDI Olie Microsoft C# .NET 0 3rd May 2007 11:33 AM
Slow Icon Drawing? Gingangooli Windows XP Basics 1 4th Dec 2005 12:43 PM
slow form drawing Konrad Microsoft Dot NET Framework Forms 3 11th Dec 2004 06:17 PM
samples of drawing on form at runtime Eric Sabine Microsoft VB .NET 1 17th Oct 2003 09:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.