我在移动面板上的标签时遇到问题。当我移动这个标签,到达顶部和左侧 (0.0) 时,标签尊重顶部和左侧。花费一半的屏幕,标签超过面板,如图所示。

我的代码:
public partial class frmStandard : Form
{
Point startposition;
}
public void MouseDown(object sender, MouseEventArgs e)
{
startposition = e.Location;
}
public void MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((Label)sender).Left = Math.Max(0, e.X + ((Label)sender).Left - startposition.X);
((Label)sender).Top = Math.Max(0, e.Y + ((Label)sender).Top - startposition.Y);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要标签不超过面板尺寸。代码中应该添加什么?
我遇到过以下代码,它使用该类的构造函数System.Drawing.Size来添加两个 System.Drawing.Point 对象。
// System.Drawing.Point mpWF contains window-based mouse coordinates
// extracted from LParam of WM_MOUSEMOVE message.
// Get screen origin coordinates for WPF window by passing in a null Point.
System.Windows.Point originWpf = _window.PointToScreen(new System.Windows.Point());
// Convert WPF doubles to WinForms ints.
System.Drawing.Point originWF = new System.Drawing.Point(Convert.ToInt32(originWpf.X),
Convert.ToInt32(originWpf.Y));
// Add WPF window origin to the mousepoint to get screen coordinates.
mpWF = originWF + new Size(mpWF);
Run Code Online (Sandbox Code Playgroud)
我认为在最后一个语句中使用 the 是+ new Size(mpWF)一种黑客行为,因为当我阅读上面的代码时,它减慢了我的速度,因为我没有立即理解发生了什么。
我尝试按如下方式解构最后一个语句:
System.Drawing.Point tempWF = …Run Code Online (Sandbox Code Playgroud) 我的在被调用mouseMoved时根本不会被调用,但在没有被调用时它会正常调用。如果我在按下鼠标按钮时移动鼠标,则不会被调用。mousePressedmousePressedmouseMoved
package src.game.main.gui_hud;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import javax.swing.SwingUtilities;
import src.game.main.Game;
public class Slider {
private Color lc,hc,fc;
private int x,y;
private int w,h;
private Runnable change;
private int lineY;
private double value = 100;
private volatile boolean canMove;
public Slider(Color bgColor,Color filledColor,Color handlerColor,Runnable onValueChange,int x,int y,int w,int h,int lineY) {
setLc(bgColor);
setHc(handlerColor);
setFc(filledColor);
change = onValueChange;
this.x = x;
this.y = y;
this.w = w;
this.h …Run Code Online (Sandbox Code Playgroud) 您好,我的鼠标在 openGL 中移动时遇到了一个奇怪的问题。这是我用鼠标移动相机的代码
void camera(int x, int y)
{
GLfloat xoff = x- lastX;
GLfloat yoff = lastY - y; // Reversed since y-coordinates range from bottom to top
lastX = x;
lastY = y;
GLfloat sensitivity = 0.5f;
xoff *= sensitivity;
yoff *= sensitivity;
yaw += xoff; // yaw is x
pitch += yoff; // pitch is y
// Limit up and down camera movement to 90 degrees
if (pitch > 89.0)
pitch = 89.0;
if (pitch < -89.0) …Run Code Online (Sandbox Code Playgroud) 我想要一些关于 javascript 项目的帮助。我想做的是有两个函数在鼠标移动时启动,但每次只有其中一个起作用
例如,如果我这样做
var mouseX;
var mouseY;
document.onmousemove = captureMouse;
document.onmousemove = function(){console.log("check");}
function captureMouse(ev){
ev = ev || window.event;
var mousePos= mouseCoords(ev);
mouseX=mousePos.x;
mouseY=mousePos.y;
document.getElementById("coordinput").value=mouseX;
return mousePos;}
function mouseCoords(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX,y:ev.pageY};
}
return{
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
Run Code Online (Sandbox Code Playgroud)
如果我删除第二个 document.onmousemove,第一个文档可以正常工作并更改输入字段的值
如果我把它留在那里,它会像它应该的那样不断地写入检查(用于调试目的),但第一个不起作用
关于如何使多个鼠标事件起作用有什么想法吗?
我没有从 stackoverflow 得到确切的解决方案/计算,所以我提出了一个问题
var timestamp = null;
var mY = 0;
$(document).mousemove(function(e) {
var now = Date.now();
currentmY = e.pageY;
mY = e.pageY;
timestamp = now;
});
Run Code Online (Sandbox Code Playgroud)
当鼠标移动垂直角度时,我需要获取速度值。
我想要一个 div 跟随光标移动并有短暂的延迟,如下所示:http ://vanderlanth.io/
正如您所看到的,“跟随者”在动画中有短暂的延迟。
我重建了一些功能不太正常的功能:
$(document).ready(function () {
$("body").mousemove(function (e) {
handleMouseMove(e);
});
function handleMouseMove(event) {
var x = event.pageX;
var y = event.pageY;
$(".cursor-follower").animate({
left: (x - 16),
top: (y - 16)
}, 16);
$(".cursor").css({
left: (x - 4),
top: (y - 4)
});
}
});
Run Code Online (Sandbox Code Playgroud)
它相当滞后,动画也不是很流畅和轻松。您还有其他解决方案吗?
要么我完全不了解事件是如何工作的,要么Delphi Prism已经疯了!!!
我有一个winform,mousedown事件和mousemove事件.每当我单击鼠标左键时,MouseDown事件会按预期触发,但ALSO MouseMove事件会在未设置时触发.
以下是我的winform设计器中的一段代码,其中方法被分配给事件.
self.ClientSize := new System.Drawing.Size(751, 502);
self.KeyPreview := true;
self.Name := 'Maker';
self.Text := 'Window Maker';
self.Load += new System.EventHandler(@self.Maker_Load);
self.FormClosing += new System.Windows.Forms.FormClosingEventHandler(@self.Maker_FormClosing);
self.Shown += new System.EventHandler(@self.Maker_Shown);
self.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDoubleClick);
self.MouseDown += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDown);
self.MouseMove += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseMove);
self.MouseUp += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseUp);
self.Paint += new System.Windows.Forms.PaintEventHandler(@self.Maker_Paint);
self.ObjectPopup.ResumeLayout(false);
self.ResumeLayout(false);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?请帮助我对此感到沮丧,因为我在程序的其他部分有鼠标移动事件.他们工作正常.我似乎无法弄清楚为什么这个特定的mousemove事件正在起作用.
在我的Qt应用程序中,我需要跟踪鼠标移动.为此,我创建了一个eventfilter,我正确安装它,因为:
bool iArmMainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove)//not working
{
iarm->printStatus("hi"); //this is for debugging
}
if (event->type() == QEvent::MouseButtonPress){
//Here some staff working correctly
}
//other staff
}
Run Code Online (Sandbox Code Playgroud)
问题是事件类型MouseMove不起作用.
任何的想法?
嘿,想要在按下并移动鼠标按钮时拖动这条贝塞尔曲线.
我这样做了:
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
qDebug()<<"in mouse move - outside if";
if((e->buttons() & Qt::RightButton) && isStart && enableDrag)
{
qDebug()<<"mouse dragging happening";
xc2=e->pos().x();
yc2=e->pos().y();
drawDragBezier(xc2,yc2);
}
}
Run Code Online (Sandbox Code Playgroud)
当我按下右键并开始在整个主窗口中移动鼠标时,这开始拖动.但是我只想在我按下鼠标按钮并在QGraphicsScene中移动鼠标时开始拖动.
怎么解决这个?
编辑:
void mySubClass1::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
qDebug()<<"in musubclass mouse press event: "<<event->pos().x()<<" "
<<event- >pos().y();
if(shape().contains(event->pos()))
{
currPosX=event->pos().x();
currPosY=event->pos().y();
qDebug()<<"currPosX currPosY: "<<currPosX<<" "<<currPosY;
}
}
}
Run Code Online (Sandbox Code Playgroud)
主窗口类是:
{
myGPath=new mySubClass1();
myScene=new QGraphicsScene;
myScene->addItem(myGPath);
ui->graphicsView->setScene(myScene);
QPointF *startPoint=new QPointF(50,50);
myPaintPath=new QPainterPath(*startPoint);
myPaintPath->quadTo(100,25,200,200);
myGPath->setPath(*myPaintPath);
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
mousemove ×10
javascript ×3
c# ×2
c++ ×2
events ×2
jquery ×2
mouseevent ×2
qt ×2
winforms ×2
.net ×1
camera ×1
delphi-prism ×1
glulookat ×1
html ×1
java ×1
mouse ×1
mousedown ×1
opengl ×1
performance ×1
wpf ×1