首先,这是相关代码:
pod
所以这段代码正在做的是当我点击画布组件时,它将绘制一个矩形的轮廓,并且当我拖动鼠标时尺寸会发生变化
然而,当我点击并开始拖动鼠标时,矩形的右下角有一个偏移量。它似乎跳到更大的尺寸第二我拖动鼠标。有趣的是,我点击画布组件的左上角越近,矩形大小越接近我用鼠标绘制的矩形。
我该如何解决这个问题?
答案 0 :(得分:1)
请记住, string attachment = "attachment; filename=Myfile.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
// My logic goes here to write file.
// Now I want to copy above file to another file.
string filepath = Server.MapPath("~/ExportedFiles/") +"Newfile.csv";
var ExcelFile = File.Create(filepath);
ExcelFile.Close();
HttpContext.Current.Response.TransmitFile(filepath);
HttpContext.Current.Response.Flush();
使用drawRect
,x
,y
,width
作为参数,您实际应该使用之间的差值点击点和拖动点
也许像......
height
并且,请勿在{{1}}方法中致电public void paintComponent(Graphics page)
{
super.paintComponent(page);
if (mouseDragged == true)
{
int x = Math.min(x1, x3);
int y = Math.min(y1, y3);
int width = Math.max(x1, x3) - x;
int height = Math.max(y1, y3) - y;
page.drawRect(x, y, width, height);
}
}