473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

gdi drawing

hi, this is a n00b question but when i draw on a panel in my form using GDI
and a pen, but when i minimize the form, or put anything in front of the item
in drawing on, the graphics go away. how can i fix this?
--
-iwdu15
Nov 17 '05 #1
6 1481
iwdu15 wrote:
hi, this is a n00b question but when i draw on a panel in my form using GDI
and a pen, but when i minimize the form, or put anything in front of the item
in drawing on, the graphics go away. how can i fix this?


Every time the form redraws the panel control it has to draw it from
scratch. So, in order for your lines to reappear you need to redraw
them every time the form redraws the panel. Handle the Control.Paint
event and do your drawing of lines in there.

Chris
Nov 17 '05 #2
how would i do that? like i have my lines being drawn on a mousemove event of
a panel...is there a simple way to save them without using overloaded
functions?
--
-iwdu15
Nov 17 '05 #3
I do this:
:
form->Paint += new PaintEventHandler( this,
$ThisClass::Paint_Event_Handler ) ;
:
void Paint_Event_Handler( Object^, PaintEventArgs^ e)
{
Graphics^ graphics = e->Graphics ;
// use graphics to draw your primitives here, like this:
Pen^ pen = gcnew Pen(Color::Red) ;
graphics->DrawRectangle( pen, 0, 0, 20, 20 ) ; // etc.
}

Note this draws your graphics every time the 'form's Paint event occurs.
This happens whenever some portion of 'form' is covered and then uncovered.
Hence, to actually SEE the graphics drawn in this way you need to execute
form->Refresh() to put on the screen what your drawing in the Paint event (I
think Refresh() causes the Paint event to fire, or at least executes the
Paint event handler).

This was all assuming /clr syntax in 2005. If you do use 2005, then I
STRONGLY recommend setting the DoubleBuffered property of your 'form' to
true, this will eliminate any flicker you might get. I personally also
double buffer manually, but that's another topic... : )

[==P==]

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
how would i do that? like i have my lines being drawn on a mousemove event
of
a panel...is there a simple way to save them without using overloaded
functions?
--
-iwdu15

Nov 17 '05 #4
iwdu15 wrote:
how would i do that? like i have my lines being drawn on a mousemove event of
a panel...is there a simple way to save them without using overloaded
functions?
--

Not sure what you mean by "overloaded functions", but yes, you would
have to save the information each time the mouse is moved, if you want
to be able to redraw it later after a screen refresh. Where and how
you save this is entirely up to you of course - a simple
std::vector<Gdiplus::Point> would probably suffice (you can then pass
this direct to Gdiplus::Graphics::DrawLines).

Nov 17 '05 #5
but how would i do this if i want to draw a line according to how the user
moves the mouse? kinda like a paint program
--
-iwdu15
Nov 17 '05 #6
iwdu15 wrote:
but how would i do this if i want to draw a line according to how the
user moves the mouse? kinda like a paint program


In the mouse handler, save information about the drawing "strokes" (probably
a collection of points). In OnPaint, redraw the lines between those points?

Arnaud
MVP - VC
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To...
7
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as...
2
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I...
3
by: Chris Saunders | last post by:
I am fairly new to .Net and C# but am familiar with the Win32 API. I wish to set the pixels of the client area of a window one at a time with a specific color. I have so far discovered that...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
1
by: YouPoP | last post by:
I am doing an app (C# 2.0) where you can draw in a panel with your mouse in "real time". I actually have 2 problems; 1- it does not really is "real time", if your mouse move fast or very fast the...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.