C# 用c语言实现图形用户界面
我必须为c winform项目创建一个图形界面。有一个背景图像和一组小的透明图片。用户必须能够将这些小图像放在背景上,选择它们并自由移动它们。我还必须计算它们之间的距离,但这是另一个步骤 我知道我可以做这样的事情: 我还发现: 我的问题是:有没有更好或最简单的解决方案来实现这一点 更新 现在图像是矩形的。如果图像重叠就没有问题了C# 用c语言实现图形用户界面,c#,winforms,graphics,C#,Winforms,Graphics,我必须为c winform项目创建一个图形界面。有一个背景图像和一组小的透明图片。用户必须能够将这些小图像放在背景上,选择它们并自由移动它们。我还必须计算它们之间的距离,但这是另一个步骤 我知道我可以做这样的事情: 我还发现: 我的问题是:有没有更好或最简单的解决方案来实现这一点 更新 现在图像是矩形的。如果图像重叠就没有问题了 如果小图像是一个问题,我可以切换简单的圆圈。重要的一点是,用户可以随时单击并移动它们。Windows演示文稿 基金会WPF可能是一个更好的解决方案。它比GDI+更倾向
如果小图像是一个问题,我可以切换简单的圆圈。重要的一点是,用户可以随时单击并移动它们。Windows演示文稿
基金会WPF可能是一个更好的解决方案。它比GDI+更倾向于图形化,而且速度也更快,因为它由DirectX提供动力。我一直在寻找一种解决方案,如何消除PictureBox中的闪烁,而不找到令人满意的东西。。。我最终使用了XNA框架和spirits中的一些2DVector。它工作得很好:
对于如何使用flickr给出了一个很好的解释,它是在游戏环境中解释的。如果你不想要flickr,你最好的选择是DirectX/XNA/OpenGL。尝试为您的应用程序找到一个带有精灵的2d框架。如果要使用WPF,则应使用画布作为容器控件。对于图像,您必须在代码隐藏文件中添加以下事件处理程序:
private bool IsDragging = false;
private System.Windows.Point LastPosition;
private void MyImage_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the right MyImage
Image MyImage = sender as Image;
// Capture the mouse
if (!MyImage.IsMouseCaptured)
{
MyImage.CaptureMouse();
}
// Turn the drag mode on
IsDragging = true;
// Set the current mouse position to the last position before the mouse was moved
LastPosition = e.GetPosition(SelectionCanvas);
// Set this event to handled
e.Handled = true;
}
private void MyImage_MouseUp(object sender, MouseButtonEventArgs e)
{
// Get the right MyImage
Image MyImage = sender as Image;
// Release the mouse
if (MyImage.IsMouseCaptured)
{
MyImage.ReleaseMouseCapture();
}
// Turn the drag mode off
IsDragging = false;
// Set this event to handled
e.Handled = true;
}
private void MyImage_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
// Get the right MyImage
Image MyImage = sender as Image;
// Move the MyImage only when the drag move mode is on
if (IsDragging)
{
// Calculate the offset of the mouse movement
double xOffset = LastPosition.X - e.GetPosition(SelectionCanvas).X;
double yOffset = LastPosition.Y - e.GetPosition(SelectionCanvas).Y;
// Move the MyImage
Canvas.SetLeft(MyImage, (Canvas.GetLeft(MyImage) - xOffset >= 0.0) && (Canvas.GetLeft(MyImage) + MyImage.Width - xOffset <= SelectionCanvas.ActualWidth) ? Canvas.GetLeft(MyImage) - xOffset : Canvas.GetLeft(MyImage));
Canvas.SetTop(MyImage, (Canvas.GetTop(MyImage) - yOffset >= 0.0) && (Canvas.GetTop(MyImage) + MyImage.Height - yOffset <= SelectionCanvas.ActualHeight) ? Canvas.GetTop(MyImage) - yOffset : Canvas.GetTop(MyImage));
// Set the current mouse position as the last position for next mouse movement
LastPosition = e.GetPosition(SelectionCanvas);
}
}
我希望这会有帮助,大卫。图像是矩形的吗?在ov重叠的情况下,它们需要如何操作?这是我正在使用的代码,我还没有为您测试它,但它应该可以工作!