473,508 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

show cross on jpg in picturebox

82 New Member
Hi

I have drawn a cross to show in a picturebox in front of a jpg which should show when the button is pressed.

If I comment out the image line the cross shows
If I comment out the cross code the image shows
but i can't paint the image with the cross in front of it
can somebody tell/show me where I'm goig wrong

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication2
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             pictureBox1.Image = Image.FromFile("C:/Users/main/Desktop/Image.jpg");
  22.             Graphics g1 = pictureBox1.CreateGraphics();
  23.             Pen myPen1 = new Pen(Color.Green);
  24.             myPen1.Width = 2;
  25.             g1.DrawLine(myPen1, 113, 80, 133, 80);
  26.             g1.DrawLine(myPen1, 123, 70, 123, 90);
  27.         }
  28.     }
  29. }
Attached Images
File Type: jpg Image.jpg (11.3 KB, 279 views)
Sep 5 '12 #1
3 2800
mrcw
82 New Member
why can't I see the jpg and the cross?

thanx

mrcw
Sep 5 '12 #2
Rabbit
12,516 Recognized Expert Moderator MVP
That's because the CreateGraphics method creates a new graphic and replaces what's there previously. What you want to do is create a graphic from an existing image using the FromImage method and then draw on top of that.
Sep 5 '12 #3
mrcw
82 New Member
thanx for your help
mark
Sep 9 '12 #4

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

Similar topics

0
3863
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
3
3924
by: Tyson Ackland | last post by:
Can someone tell me how you go about handling events where your window might be obscured and then when you bring it to the foreground, you want your picturebox control to be repainted instead of...
5
4873
by: BrianW | last post by:
I am working on a program that has multiple picturebox controls that a user is allowed to move around which are contained within a panel control for visual placement. In my mousedown event, I set...
6
4729
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the...
0
937
by: Feride | last post by:
hello, i'm trying to show a pictureBox named pb1 on some other pictureBoxes which are the elements of a pictureBox array called pbs. To watch the differences, i made use of a timer. here are the...
4
3687
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep...
4
5544
by: gerardianlewis | last post by:
Any help appreciated. (VB.NET under XP and Vista, SP1 installed) My code, inherited from a VB6 version of an app that ran under W98, loads an image from a file into a PictureBox. The user may...
5
5371
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
5
6100
mahboobeh
by: mahboobeh | last post by:
hi i have tow picturebox and i want to show the first with a low transparency on top of the another one. its mean i want to transparent above picturebox and show every thing that behind of it like...
1
1776
by: Chocolade | last post by:
I have a new form. Now in form1 im showing images in picturebox1. Now i did a double click event of picturebox1 and when you click double on the picturebox1 its openning a new form. On the new...
0
7224
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
7118
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
7323
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,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
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
7493
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
5625
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,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.