473,499 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with refreshing picture

3 New Member
Hi,

I created small application, which is suppose to draw objects on jpg file ( loaded into picturebox ). Coordinates of objects are provided by user ( by clicking on picturebox ). Here are some code samples:

Expand|Select|Wrap|Line Numbers
  1.  public void ryspkt(MouseEventArgs e)
  2.         {
  3.             if (pictureBox1.Image != null)
  4.             {
  5.  
  6.                 if (e.Button == MouseButtons.Left)
  7.                 {
  8.                   rect[nrprs++] = new Rectangle(e.X, e.Y,2,2);
  9.                   pictureBox1.Invalidate();
  10.                 }
Expand|Select|Wrap|Line Numbers
  1.        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  2.         {
  3.             ryspkt(e);
  4.         } 
Expand|Select|Wrap|Line Numbers
  1.  private void pictureBox1_Paint(object sender, PaintEventArgs e)
  2.         {
  3.                 //g = e.Graphics;
  4.                 g = Graphics.FromImage(pictureBox1.Image);
  5.                 for (int i = 0; i < nrprs; i++)
  6.                     {
  7.                         g.FillEllipse(b, rect[i]);
  8.                     }
  9.         }
So - the problem is that ellipses are drawn with delay - I mean that first is drawn on 2nd click, 2nd ellipse on 3rd click, and so on. I assume that there is issue with validating picturebox, but I can't find what I'm doing wrong :/

There is no issue at all if I switch from "g = Graphics.FromImage(pictureBox1.Image)" to "g = e.Graphics" but if I do this I can't save image properly ( drawn object just disappear ).

Any suggestions ? :)

Regards,
Piotr
Nov 19 '10 #1
3 1305
Potr Milczarek
3 New Member
Ok, I fixed it :) Refreshing picturebox before using invalidate was sufficient.

However, I have secong question - is there any simple way to erase drawn ellipses ( and keep image ) when I click "clear" button ?

Thanks,
Piotr
Nov 20 '10 #2
GaryTexmo
1,501 Recognized Expert Top Contributor
No, I don't think you can erase in this fashion. You're drawing right onto the image so once once drawn, it's there.

However, you can do a few things...

1) Keep a copy of the original image. When you want to clear, just restore the image itself.

2) Don't draw on the actual image at all. Keep track of the draw operations in a list, then in the Paint method draw the picture, then the various other things on top of that using the graphics object for whatever control you're painting on. This will let you undo/redo if need be as well.
Nov 22 '10 #3
Potr Milczarek
3 New Member
1st method worked perfectly, thank you very much !
Nov 23 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
22887
by: bb | last post by:
I am trying to force an iframe to refresh from the server using the following javascript: document.frames("frm").document.location.reload(true) The iframe html is: <iframe id="frm" name="frm"...
1
2072
by: Bjoern Wolter | last post by:
ich have following problem on the left side i have an picture, an on the right side will be text. the text is larger than the picture height, so the text continues under the picture, how can i ...
1
1219
by: Gilgamesh | last post by:
I have a few picture boxes on a C# form, with each one loading an image from a different file. If I run the application on my computer, everything looks good. If I run the app on any other...
0
1206
by: Alpha | last post by:
Hi, I have a listbox and a textbox which is bind to the same dataset's column. So the selected item is display in the textbox availbe for editing. When I change the text in the textbox it has...
4
2056
by: Jhonatas M. Rodríguez | last post by:
Hello Everybody how are you everybody ?... i have a problem with picture box, i want copy a image from the clipboard, and me can to copy a image if the image is a bitmap(extension bmp), but if...
0
773
by: sunil | last post by:
hello there, I am working on vb.net application and i am facing the following problem I have a form frm1.vb and from that on clicking some button I have to open other form frm2.vb. What i want...
2
1013
by: indhu | last post by:
Hi all, Form name--sceneimage i ve field like sequence(txt), scene(number), shot(images) per shot has 3 images like A, B, C, depends some time 2 or 1also. so how to handle this. should i...
2
2840
by: millertime90 | last post by:
Hi basically my problem is I have 2 drop down menus populated by my database the first populated by a field in the database and the 2nd populated with a relation to the value selected in the first...
4
1663
by: shahidrasul | last post by:
i display a pic on picture box and then i want to display another pic after some seconds but problem is that first image is not displaying only display 2nd image 1... display first picture from...
5
1717
by: zamuel | last post by:
Hey everyone. I have a strange problem with PHP site. This only happens in IE 6. So, when user logs in there is a placeholder for user's own picture. Also there is a form where this picture can...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.