473,543 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rectangle in a pictureBox

Hi all

I have a picturebox which I will have a image loaded to it and some
text fields with coordinates. I am drawing a rectangle according to the
coordinates in the text fields.

Rectangle r = new Rectangle(int.P arse(this.txt_L eft.Text),
int.Parse(this. txt_Top.Text), ControlWidth, ControlHeight);
pictureBox2.Cre ateGraphics().D rawRectangle(ne w Pen(Color.Red, 1), r);

This is working fine, draw the red rectangle. But I want to clear the
rectangle when I change the coordinates. Does somebody knows how to do
that?

Thanks

Jun 16 '06 #1
3 16121
em*******@gmail .com wrote:
Hi all

I have a picturebox which I will have a image loaded to it and some
text fields with coordinates. I am drawing a rectangle according to the
coordinates in the text fields.

Rectangle r = new Rectangle(int.P arse(this.txt_L eft.Text),
int.Parse(this. txt_Top.Text), ControlWidth, ControlHeight);
pictureBox2.Cre ateGraphics().D rawRectangle(ne w Pen(Color.Red, 1), r);

This is working fine, draw the red rectangle. But I want to clear the
rectangle when I change the coordinates. Does somebody knows how to do
that?


Why don't you use a class inherited from Control and override OnPaint to
do all the drawing? You can use the DrawImage function to draw the image
that the PictureBox draws right now. And use DrawRectable as above.
This will also make sure that your coordinate rectangle will get cleared
every time OnPaint gets called.

Max
Jun 16 '06 #2
Markus Stoeger wrote:
em*******@gmail .com wrote:
Hi all

I have a picturebox which I will have a image loaded to it and some
text fields with coordinates. I am drawing a rectangle according to the
coordinates in the text fields.

Rectangle r = new Rectangle(int.P arse(this.txt_L eft.Text),
int.Parse(this. txt_Top.Text), ControlWidth, ControlHeight);
pictureBox2.Cre ateGraphics().D rawRectangle(ne w Pen(Color.Red, 1), r);


I forgot.. Pens should be disposed (they consume GDI handles):

using (Pen pen = new Pen(whatever)) {
graphics.DrawRe ctangle(pen, ...);
}

Max
Jun 16 '06 #3
All right. I'll give a shot and let you know!

Thanks!

Markus Stoeger wrote:
Markus Stoeger wrote:
em*******@gmail .com wrote:
Hi all

I have a picturebox which I will have a image loaded to it and some
text fields with coordinates. I am drawing a rectangle according to the
coordinates in the text fields.

Rectangle r = new Rectangle(int.P arse(this.txt_L eft.Text),
int.Parse(this. txt_Top.Text), ControlWidth, ControlHeight);
pictureBox2.Cre ateGraphics().D rawRectangle(ne w Pen(Color.Red, 1), r);


I forgot.. Pens should be disposed (they consume GDI handles):

using (Pen pen = new Pen(whatever)) {
graphics.DrawRe ctangle(pen, ...);
}

Max


Jun 16 '06 #4

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

Similar topics

15
9037
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for the purpose of learning to work with C++. It therefore makes some sense for me to give the situation the amount of consideration presented below. To...
3
2456
by: | last post by:
I am having a hard time understanding the logic behind the Rectangle object. My problem has to do with the way the rectangle treats the "Width" property. For example, take the following rectangle object. Rectangle myRec = new Rectangle(0, 0, 2, 2); If you draw this rectangle on the screen you will end up with a rectangle like the one...
6
4773
by: Brad Shook | last post by:
Can someone point me to an example or post some code on how to allow a user to draw a rectangle on top of an image and retrieve the coordinates and dimensions of it. They will also need to be able to move it around on the picture and delete it. Thanks Brad Shook
5
4688
by: DazedAndConfused | last post by:
I have a rectangle around text that I want to fill in with color. I do not know the height of the rectangle until I actually go through and draw out the text. Is there a way of filling in the rectangle that will allow the text to show through? I did try: myColor = Color.FromArgb(127, Color.GreenYellow) Dim fillBrush As New...
4
9267
by: fripper | last post by:
I am a real novice when it comes to the graphics class in VB 2005. I have a windows app with a large picture box control with a black background ... except for a small rectangle that has an image in it. A timer fires every second or so and when it does I want to move the small rectangle within the picture box to another location within the...
3
2734
by: Peter | last post by:
I have the following code, which draws a ractangle on a picture box, but the rectangle does not become visible until I overlay another Window over the picture box and remove this window. How can I fix this problem? private static void PictureBox1_paint( object sender, PaintEventArgs e ) { // Get Graphics Object Graphics g = e.Graphics;
10
5453
by: kimiraikkonen | last post by:
Hi, If previous post was missing, here's the complete one: I'm trying to draw a rectange on a picturebox image using mouse move event but the problem is that the rectangle selection / drawing cannot be done from starting from bottom-right to up-left. The only selection i'm allowed to do is starting from top-left towards bottom-right...
0
2325
by: Red Head | last post by:
Hello I've written some code to draw a rectangle on a picture box when the user moves the mouse. (the previous rectangle is cleared) This works fine but the very first rectangle is not removed from the screen. here is my code private Rectangle r = new Rectangle(new Point(0,0), new Size(0,0));
1
1270
by: dharmendermca | last post by:
i'want to draw a rectangle in picturebox and then drag it anywhere inside the picturebox and where i drop it that portion must be displayed in another picturebox using vb.net
0
7408
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7735
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5885
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5271
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
636
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.