给了PictureBox新的位置坐标并使用PictureBox.Refresh()刷新后,PictureBox在旧坐标和新坐标都出现了 老坐标并未消失,求解答如何在给PictureBox定义新坐标使用Refresh()刷新后,使PictureBox的上一个坐标消失?
在使用Refresh()进行刷新后,PictureBox的旧坐标并未消失
PictureBox.location = new Point (PictureBox.X+ 10,PictureBox.Y+20);
PictureBox.Refresh();
给PictureBox定义新坐标使用Refresh()刷新后,使PictureBox的上一个坐标消失?
(求指导。)
对于图片框移动,我不建议使用这种方法。你去查找下c# TranslateTransform类。
//
// 摘要:
// Translates (moves) an object in the 2-D x-y coordinate system.
public sealed class TranslateTransform : Transform
{
//
// 摘要:
// Identifies the System.Windows.Media.TranslateTransform.X dependency property.
//
// 返回结果:
// The identifier for the System.Windows.Media.TranslateTransform.X dependency property.
public static readonly DependencyProperty XProperty;
//
// 摘要:
// Identifies the System.Windows.Media.TranslateTransform.Y dependency property.
//
// 返回结果:
// The identifier for the System.Windows.Media.TranslateTransform.Y dependency property.
public static readonly DependencyProperty YProperty;
//
// 摘要:
// Initializes a new instance of the System.Windows.Media.TranslateTransform class.
public TranslateTransform();
//
// 摘要:
// Initializes a new instance of the System.Windows.Media.TranslateTransform class
// and specifies the displacements in the direction of the x- and y- axes.
//
// 参数:
// offsetX:
// The displacement in the direction of the x-axis.
//
// offsetY:
// The displacement in the direction of the y-axis.
public TranslateTransform(double offsetX, double offsetY);
//
// 摘要:
// Gets or sets the distance to translate along the x-axis.
//
// 返回结果:
// The distance to translate (move) an object along the x-axis. The default value
// is 0.
public double X { get; set; }
//
// 摘要:
// Gets or sets the distance to translate (move) an object along the y-axis.
//
// 返回结果:
// The distance to translate (move) an object along the y-axis. The default value
// is 0.
public double Y { get; set; }
//
// 摘要:
// Gets a System.Windows.Media.Matrix representation of this System.Windows.Media.TranslateTransform.
//
// 返回结果:
// A matrix that represents this System.Windows.Media.TranslateTransform.
public override Matrix Value { get; }
//
// 摘要:
// Creates a modifiable copy of this System.Windows.Media.TranslateTransform by
// making deep copies of its values.
//
// 返回结果:
// A modifiable deep copy of the current object. The System.Windows.Freezable.IsFrozen
// property of the cloned object returns false even if the System.Windows.Freezable.IsFrozen
// property of the source is true.
public TranslateTransform Clone();
//
// 摘要:
// Creates a modifiable copy of this System.Windows.Media.TranslateTransform object
// by making deep copies of its values. This method does not copy resource references,
// data bindings, and animations, although it does copy their current values.
//
// 返回结果:
// A modifiable deep copy of the current object. The System.Windows.Freezable.IsFrozen
// property of the cloned object is false even if the System.Windows.Freezable.IsFrozen
// property of the source is true.
public TranslateTransform CloneCurrentValue();
protected override Freezable CreateInstanceCore();
它的属性doubleX,DoubleY就是移动变化的值。将这个类的对象赋值给控件的RenderTransform属性就好啦。我做的控件移动都是用的这种方法。
如果想扩展开可以进行缩放。旋转等功能。需要参考TransformGroup功能。_group就是TransformGroup对象。
_group.Children.Add(new TranslateTransform()); // 移动
_group.Children.Add(new ScaleTransform()); // 缩放
_group.Children.Add(new RotateTransform()); // 旋转
我用下面的代码测试了没有问题。而且修改坐标并不需要refresh。
你是不是拷贝了一个picturebox。
pictureBox1.Location = new Point(pictureBox1.Location.X + 10, pictureBox1.Location.Y + 20);
pictureBox1.Refresh();