移动窗口的方法
我想做这样的事情: 我有带有图片的表单,当我单击这些表单时,我想显示带有该图片的新窗口(它必须只是图片,没有一些工具箱或边框)。继续我希望能够移动这个窗口(当我按下鼠标上的按钮并移动鼠标时,这个窗口必须随着我的光标移动,当我移动鼠标时向上按钮窗口不会移动)。
我这样做: 制作新的窗口窗体,删除工具栏、边框,添加图片框,添加 mouseDown、mouseUp 和 mouseMove 方法。方法代码:
private void FormZdjecie_MouseDown( object sender, MouseEventArgs e ) {
buttonUp = false;
previous = e.Location;
}
private void pictureBox1_MouseUp( object sender, MouseEventArgs e ) {
buttonUp = true;
}
private void pictureBox1_MouseMove( object sender, MouseEventArgs e ) {
if ( !buttonUp ) {
Point diff = new Point();
diff.X = e.X - previous.X;
diff.Y = e.Y - previous.Y;
this.Location = new Point( this.Location.X + diff.X, this.Location.Y + diff.Y );
previous = e.Location;
}
}
我可以工作,但刷新速度很慢。它如何像 Windows 窗体一样工作(当我移动普通的 Windows 窗体时,它看起来很好),但我的方法看起来很糟糕;p 知道如何制作它吗?
I want do something like that:
I have form with pictures, when I click on ones, I want to display new window with this picture (it must be only picture, without some toolbox or border). Continuing I want to be able move this window (when I press button on mouse and move mouse, this window must move with my cursor, when I up button window won't move when I move mouse).
I do it like that:
make new window form, remove toolbar, border, add pictureBox, add method on mouseDown, mouseUp and mouseMove. Code for method:
private void FormZdjecie_MouseDown( object sender, MouseEventArgs e ) {
buttonUp = false;
previous = e.Location;
}
private void pictureBox1_MouseUp( object sender, MouseEventArgs e ) {
buttonUp = true;
}
private void pictureBox1_MouseMove( object sender, MouseEventArgs e ) {
if ( !buttonUp ) {
Point diff = new Point();
diff.X = e.X - previous.X;
diff.Y = e.Y - previous.Y;
this.Location = new Point( this.Location.X + diff.X, this.Location.Y + diff.Y );
previous = e.Location;
}
}
I work, but it very slow refresh. How do it to work like windows form (when I move normal windows form it look fine), but my method look badly ;p Any idea how to make it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 WinAPI。请参阅此处。
You need to use the WinAPI. See here.