c# - How to correctly position a "X" in a rectangle? -


i have next problem: have rectangle 10 lines , 10 columns. when press on square have draw "x" letter. well, when press on right half, or on bottom half of square, "x" drawn in next right square, respectively in below square. should when press wherever on square, "x" drawn on respective square?

my code is:

private void panel2_mouseclick(object sender, mouseeventargs e) {     txtx.text = convert.tostring(e.x);     txty.text = convert.tostring(e.y);      var data = file.readalllines(handleclinet.getpath().replace("client","server"));      if (e.x >= 20 && e.y >= 20 && e.x <= 220 && e.y <= 220)     {             var graph = (sender panel).creategraphics();             const int redint = 255; //255 example, give u know             const int blueint = 255; //255 example, give u know             const int greenint = 255; //255 example, give u know              var p = new pen(color.fromargb(redint, blueint, greenint));             var newex = (int)math.round(                 (e.x / (double)20), midpointrounding.awayfromzero) * 20;              var newey = (int)math.round(                 (e.y / (double)20), midpointrounding.awayfromzero) * 20;              rectanglef rectf1 = new rectanglef(newex, newey, 20,20);             graph.drawstring("x", new system.drawing.font("arial", 16), brushes.blue, rectf1);     } } 

and rectangle like:

enter image description here

many in advance!

it seems issue using midpointrounding.awayfromzero

it seems me if sum have calculate position want draw 'x' gives result 6.6, want have in position 6, not position 7, realistically want replace line with:

int newex = math.floor((e.x / (double)20)) * 20; 

... , same y calculation too

this should ensure whatever result gives, should not jump next box.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -