c# - Client/Screen Coordinate Conversion -


i've fallen down deep rabbit hole. there 2 issues i've dealt with. don't think have solution first issue (mentioned in next paragraph), guess real question how heck use pointtoscreen/pointtoclient reliably.

i want use balloons show validation failures user control i've written. way use tooltip isballoon set. in validation error handler, call show() on tooltip user-control parameter. works if click on control, not if use tab leave control. i've tried hacks queuing task on thread sleep bit, try show balloon. nothing works.

so, decided try go around , use main window ("this") parameter , specify coordinates, i.e.:

_balloon.show(text, this, pos);   

i can't seem calculate position (pos), though.

i'd position bottom right corner of control, here is:

var clientbottomright = new point(_ctrlcallbackphone.width, _ctrlcallbackphone.height);   

then, try actual screen coordinates of spot so:

var screenposition = _ctrlcallbackphone.pointtoscreen(clientbottomright);   

finally, try coordinates on main form ("this") so:

var mainposition = this.pointtoclient(screenposition);   

then show balloon. have twice because of windows bug.

_balloon.show(string.empty, this, mainposition);   _balloon.show(text, this, mainposition);   

the result above , left of should be. although margin of error looks size of title bar, don't see how that's it. i'm getting screen coordinates of spot, , asking client coordinates of same spot.

now, of course, if has real solution making balloon work when tab away control, i'd stop caring screen coordinates thing. imagine sort of windows weirdness, though, won't able solve.

i don't understand why works, results in correct coordinates:

var mainposition = this.pointtoclient(screenposition); mainposition = new point(                mainposition.x + systeminformation.verticalresizeborderthickness,                mainposition.y + systeminformation.captionheight + systeminformation.horizontalresizeborderthickness); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -