473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PointToScreen (Client vs screen coordinates) trap for rubberrectangle s

keywords: logical coordinates, page coordinates, world coordinates,
device coordinates, physical coordinates, screen coordinates, client
coordinates. offset rectangle. WYSIWYG rubber rectangle problem,
bounded rectangle problem. PointToClient, PointToScreen

Beware this newbie trap for the unwary. It goes by various names (in
some old MFC literature I saw some of the keywords above). Whenever
doing comparisons between points, especially using rubber or bounded
rectangles, you want to convert into screen coordinates (aka logical
coordinates, page coordinates, world coordinates) from client
coordinates (aka device coordinates, physical coordinates).

Below is the pseudocode. If you don't do this, whenever you use a
'rubber rectangle' (also called a bounding rectangle, it's something
you create with a mouse to define an area on your screen), you will be
off by an offset, and you rubber rectangle won't quite be capturing
the area on the screen you think it's at. The offset depends on how
small your client window is relative to the full sized window. So, if
you expand you client window to full size, you'll never have this
problem, but if the user doesn't expand the window, the problem
remains unless you use the solution below. The solution is to employ
PointToScreen method, but it has to be done in the manner shown
below. A quick and dirty workaround to the below, which is nasty IMO,
is simply to require the form be always maximized (I've seen programs
do this, but it's not user friendly IMO).

BTW, as an aside, whenever using a rubber rectangle always "normalize
it" meaning whether the user creates it from left to right or right to
left, it gives the same coordinates, otherwise, if it's not
normalized, you'll only capture the screen when you create the rubber
rectangle a certain way (say dragging left to right). Keyword search
"normalize rectangle". In MFC they used to have a function to do
this, but in C# you have to do it yourself. Also you should search
the web for how to do a rubber rectangle; there's lots of examples.

RL

//pseudocode

public void DoSomethingWith ABoundedRectang le (Rectangle boundedRect,
object sender, MouseEventArgs e)
{

Control control = (Control)sender ; //required for
PointToScreen!

// Calculate points always using the PointToScreen
method.
foreach (Point Y in MyPointList)
{
Point myfirstPoint = new Point();
myfirstPoint.X = Y.X; myfirstPoint.Y= Y.Y; //etc.etc
myfirstPoint = control.PointTo Screen(myfirstP oint); //
prevents offset

if (boundedRect.Co ntains(myfirstP oint))
{
//Do Something //now the bounded rectangle will not be
offset
}
}

/////////////////// the above function was called by the below event
handler

private void Form1_MouseUp(o bject sender, MouseEventArgs e)
{

// myRubberR; //create a rubber rectangle, should exist here

DoSomethingWith ABoundedRectang le (myRubberR, sender,e);
}
//////////////////////////

Aug 22 '08 #1
0 8947

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

Similar topics

15
4490
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
1
1244
by: al | last post by:
Greetings, How should I adjust my text size on my 21(inch) screen so it looks nicely fit on client's 17(inch), all are with IE 6? I use 'Larger' text size but it appears large on client's and affecting the overall look of the aspx page. MTIA, Grawsha
0
1242
by: Rob | last post by:
I have set up an ImageButton on a webform. I am using it as a Image Map. I use it's click event to return the coordinates to the server. But here is the problem. The coordinates are affected by the screen's DPI setting. My display is set to 120 DPI instead of the usual 96 DPI which is 125% more than normal. To get the correct coordinate I need to divide the X and Y values by 1.25. How can I get the correct coordinates regardless of...
2
3391
by: Armin | last post by:
Hello I want get the Screen Coordinates of a Control. I do this with Control.PointToScreen. vlob_Point = Me.PointToScreen(New System.Drawing.Point(0, 0)) This works fine with a Single Monitor but
1
9424
by: Colin McGuire | last post by:
Thanks everyone for help in my previous post. Using the "Point.op_Addition" from the previous post I have to now focus on the real problem. I need to manually position a new form so that its upper left hand corner is positioned exactly in the middle of the button that was pressed (Button1). I can't seem to get the knack of Location() and PointToScreen() to position the new form here. According to the help, location() is to do
1
1689
by: zoneal | last post by:
OS: Win XP Language: VB.net or C# I have a program where I need to launch 2 separate instances of an App called "Main.exe". Each instance will need to be piped to there own video display. Both displays need to be running at a screen resolution of 640x480. I am able to force to screen resolution of the display that the app is
11
5319
by: AliR | last post by:
Hi everybody! I need a script, which calculates screen coordinates of given object (e.g. textbox or div). By "screen coordinates" I mean offset from upper left corner of the screen (not frame or browser window). Thanks in advance.
3
1480
by: Peter Oliphant | last post by:
I'm programming using MS VS VC++ 2008 Express (Beta 2) in /Cli pure mode. I've found the Screen class. With it I can very easily get the count and all the data on the various Screens attached to a system, whether it be a single screen or multiple screen system. I believe the FromControl method of the Screen class can be used to determine which Screen a Form is on. But I can't find how I can place or move a Form onto the Screen of my...
7
3560
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 excellent transforms specified on Bob Powell's site, I still wonder if there's an easier way of centering it than the following procedure? Here is what I do now (it's awkward but it works): 1) I follow the transforms specified on Bob Powell's...
0
9363
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...
0
8237
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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();...
0
4593
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.