473,756 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about rectangle?

you are given two rectangles, each defined by an upper left(UL) corner and a
low right(LR)corner ,Both rectangles' edges will always be parrallel to the x
or y axis ,Write a window program with c# that user can use mouse to draw
the rectangle add the program will determines whether the two rectangles
overlap. For convenience, you may use the following structs:
Struct point{
Int x;
Int y;
}
Struct rect{
struct point UL;
struct point LR;
}
The function prototype is As following:
int overlap(struct rect A,struct rect B);
Nov 15 '05 #1
4 1506
Um, this sounds like home work or some test :P
Note all triangles will be like this one, but the position may wary.
If you get stuck, ask specific problems.

UL
Y |\
| | \
| |__\LR
|
|_______x

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
I want to know the best way to draw rectangle on form,
I write some code in mouseup() and mousemove(),mou sedown(),
but it not work, i cant save the rectangle's data
Nov 15 '05 #3
Well, you only need two points to know the rectangle since you can
calculate the third one.
UL and LR. The corner point (CP) will be (UL.x, LR,y).

Drawing the triangle can be done by DrawLine between each of the points
(UL, LR), (LR, CP), (CP, UL)
Capture the UL on mousedown, and use mousemove coordinates for LR until
mouseup.

If you call Invalidate() after mousemove events/mouseup you can erase the
old triangle by drawing it using the background color (you need the old LR
for that) before drawing the new triangle.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
thanx
i will try
"Morten Wennevik" <Mo************ @hotmail.com>
??????:oprykoc5 t8hntkfz@localh ost...
Well, you only need two points to know the rectangle since you can
calculate the third one.
UL and LR. The corner point (CP) will be (UL.x, LR,y).

Drawing the triangle can be done by DrawLine between each of the points
(UL, LR), (LR, CP), (CP, UL)
Capture the UL on mousedown, and use mousemove coordinates for LR until
mouseup.

If you call Invalidate() after mousemove events/mouseup you can erase the
old triangle by drawing it using the background color (you need the old LR
for that) before drawing the new triangle.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5

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

Similar topics

7
1665
by: Porky Pig Jr | last post by:
Hello, I"m still learning Python, but going through the Ch 5 OOP of Nutshell book. There is discussion on __slots__, and my understanding from reading this section is that if I have a class Rectangle (as defined in some prior sections), and then I provide definition class OptimizedRectangle(Rectangle): __slots__ = 'width', 'heigth' I can use the instance of OptimizedRectangle, say, x, with 'width' and 'heigth', but (quoting the book)...
2
1648
by: padawan | last post by:
I have a winforms control that draws a rectangle for a boarder and positions some graphical elements around the control to create the boarder effect I desired. In the control I have overriden the onpaint event and added the code to draw my rectangle and position my graphic items: Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) e.Graphics.Clear(Color.FromArgb(255, 255, 255))
1
4561
by: Yuelin | last post by:
Hi, thanks for the answers to my previous questions. Now I have a question on drawing in C#: For example I have written following code to draw a rectangle on a form: protected override void OnPaint ( PaintEventArgs e) { Graphics dc = e.Graphics; Pen BluePen = new Pen(Volor.Blue, 3);
5
1094
by: Crirus | last post by:
What do you think about this approaches, wich one is the best? For x As Integer = u.GetViewBounds.X To u.GetViewBounds.X + u.GetViewBounds.Width For y As Integer = u.GetViewBounds.Y To u.GetViewBounds.Y + u.GetViewBounds.Height Dim Dx As Integer = x - u.Location.X Dim Dy As Integer = y - u.Location.Y If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange Then 'punctul e in cercul vizual
1
641
by: CJ Taylor | last post by:
Alright, I cannot figure out what I'm doing wrong here. As some of you know I've been stripping out C1 out of my current project, and going back to native .NET controls. However, on one of my grids I have the following code... ....
9
1888
by: rut | last post by:
If I have a picturebox with a background image and I want to 1. Display text atop of the background and 2. Have transistions between text; ie, when the text changes, the screen can fade out/in or have a windowblind type transition,etc. How do you create transitions in a picture box in conjunction with displaying text? (Using vb.net.
3
2467
by: Nebulism | last post by:
Hi everyone! Earlier I asked a question about mouse interaction with a GUI. I have found a pretty comprehensive script that is supposed to work <mod edit: link removed, source inserted>:# This class describes a generic method of drawing rubberbands # on a wxPython canvas object (wxStaticBitmap, wxPanel etc) when # the user presses the left mouse button and drags it over a rectangular # area. It has methods to return the selected area by...
6
1099
by: Dom | last post by:
I have a class that has a System.Drawing.Rectangle as a member, called m_Rect. I set it up as a property, like this: get { return m_Rect;} set { m_Rect = value;} Now in my main code I want to do the following: myObject.Rect.Width = width; myObject.Rect.Height = height;
5
2214
by: Dom | last post by:
is there a difference between the following: Rectangle r = new Rectangle (10,20,30,40); Rectangle r = Rectangle.FromLTRB(10,20,30,40); Also, I guess I'm not sure why Structs are created with a NEW keyword, anyway. Aren't they located on the stack, like values, and isn't NEW used to create space on the heap? Dom
4
2388
by: raiderdav | last post by:
I understand how the ternary operator (question mark - ?) works in an if/else setting, but what does it mean when used as a type? For instance, I'm trying to add a get/set in some existing code, but the return type doesn't match: Rectangle? m_textArea = null; public Rectangle TextArea { set { m_textArea = value; } get { return m_textArea; }
0
9456
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6534
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3805
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
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.