Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

About drawing something on a Control.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
linuxfedora@yahoo.com.hk - 05 Oct 2007 05:19 GMT
i have added a Panel with size = (100, 100). Then i would like to draw
a Line on that Panel. So i write:

I write some codes on the OnPaint event of the Panel:
private void panel_Paint(...)
{
Graphics g = e.Graphics;
g.DrawLine(new Pen(Colors.Red, 6), new Point(0, 0), new Point(100,
100));
}

Then it can draw a line on the Panel, but when part of the Panel is
covered by other windows, the hope Panel will call OnPaint, and the
whole line will be redraw, is there any way to prevent it??Thanks
Göran Andersson - 05 Oct 2007 07:08 GMT
> i have added a Panel with size = (100, 100). Then i would like to draw
> a Line on that Panel. So i write:
[quoted text clipped - 10 lines]
> covered by other windows, the hope Panel will call OnPaint, and the
> whole line will be redraw, is there any way to prevent it??Thanks

The Graphics object that you get in the event arguments is cropped to
the area that needs to be redrawn. If you are using that, you can't draw
 anywhere that you aren't supposed to.

Signature

Göran Andersson
_____
http://www.guffa.com

linuxfedora@yahoo.com.hk - 05 Oct 2007 07:16 GMT
if i want to draw something on the control, then how can i do it?
For example, when i call function named WriteSomeThingOnPanel(),

Then there will be a line drawn on Panel?

I have tried to get the Graphics of the Panel by
Graphic.FromHwnd(panel.Handle);
then draw the line, but nothing can be drawn?Thanks
linuxfedora@yahoo.com.hk - 05 Oct 2007 08:00 GMT
This is source code of my testing program:
http://www.teleeye.com/marketing/Software/PlaybackLogCtrl_sample.zip
(Run in Visual Studio 2005)
In the source, i used a tableLayout Named logCamTableLayout and put
many logCamPanel on them, and then draw a Line on each of the
logCamPanel, and when these logCamPanel is redraw, it will call
OnPaint, and i will write a line that, but i find the screen will be
flicking when it needs to redraw. Does anyone know how to solve it?
Thanks
Peter Duniho - 05 Oct 2007 09:26 GMT
> This is source code of my testing program:
> http://www.teleeye.com/marketing/Software/PlaybackLogCtrl_sample.zip

Please don't post links to your code.  Post an actual code sample with
your post.

And please don't just copy and paste whatever code you have.  Post a
concise-but-complete sample of code.  "Concise" means you have removed
_everything_ from the code that is not absolutely required in order to
reproduce the problem.  "Complete" means there is _nothing_ left out of
the code that is needed in order to compile and run it.

That said, you may not need to fix that mistake.  Specifically...

> In the source, i used a tableLayout Named logCamTableLayout and put
> many logCamPanel on them, and then draw a Line on each of the
> logCamPanel, and when these logCamPanel is redraw, it will call
> OnPaint, and i will write a line that, but i find the screen will be
> flicking when it needs to redraw. Does anyone know how to solve it?

It sounds to me as though the problem you're concerned about is simply
the visual effect of the control erasing its background and then you
drawing the line again.  This makes the line seem to flicker.

You can usually solve this easily simply by setting the DoubleBuffered
property of the control to "true".  Note that to do this, you have to
have your own class derived (at some point) from Control.  IMHO, if you
want to do custom drawing, this is a better way anyway.  So make a new
class, derived from Panel, and in the constructor set the DoubleBuffered
property to "true.  Then instead of subscribing to the Paint event, just
override the OnPaint() method in the class.

Pete
linuxfedora@yahoo.com.hk - 05 Oct 2007 10:05 GMT
Sorry, i have removed most of the code from the original source before
posting.

Okey, thank, then i should search for document on doublebuffering and
try to use a custom panel to draw the line. THanks
Göran Andersson - 05 Oct 2007 08:55 GMT
> if i want to draw something on the control, then how can i do it?
> For example, when i call function named WriteSomeThingOnPanel(),
[quoted text clipped - 4 lines]
> Graphic.FromHwnd(panel.Handle);
> then draw the line, but nothing can be drawn?Thanks

You use the Paint event, just as in the code that you posted. The event
arguments contains a reference to the graphics object that should be
used for drawing, just as in the code that you posted.

To trigger the Paint event, you call the Invalidate method on the control.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.