0
我使用下面的代碼拖動&將圖像拖放到畫布上並藉助於縮放縮放,我可以通過觸摸來縮放標籤上的圖像。但我想借助鼠標在桌面上做同樣的事情。可能嗎。我是UWP編程新手,請幫助我。Zoom_In&Zoom_Out在UWP中使用鼠標在畫布上顯示圖像Appliction
void Drag_ManipulationDelta1(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Move the rectangle.
//dragTranslation.X += e.Delta.Translation.X;
//dragTranslation.Y += e.Delta.Translation.Y;
TextBlock text = sender as TextBlock;
CompositeTransform ct1 = text.RenderTransform as CompositeTransform;
ct1.ScaleX *= e.Delta.Scale;
ct1.ScaleY *= e.Delta.Scale;
if (ct1.ScaleX < 1.0) ct1.ScaleX = 1.0;
if (ct1.ScaleY < 1.0) ct1.ScaleY = 1.0;
if (ct1.ScaleX > 4.0) ct1.ScaleX = 4.0;
if (ct1.ScaleY > 4.0) ct1.ScaleY = 4.0;
//Checking with canvas boundary so that image wont go behind canvas
if ((ct1.TranslateX + e.Delta.Translation.X) <= (my_canvas.ActualWidth - text.ActualWidth) && ct1.TranslateX + e.Delta.Translation.X >= 0)
ct1.TranslateX += e.Delta.Translation.X;
if ((ct1.TranslateY + e.Delta.Translation.Y) <= (my_canvas.ActualHeight - text.ActualHeight) && ct1.TranslateY + e.Delta.Translation.Y >= 0)
ct1.TranslateY += e.Delta.Translation.Y;
if ((ct1.TranslateX + e.Delta.Translation.X) <= (my_canvas.ActualWidth - text.MinWidth) && ct1.TranslateX + e.Delta.Translation.X >= 1150)
ct1.TranslateX -= e.Delta.Translation.X;
if ((ct1.TranslateY + e.Delta.Translation.Y) <= (my_canvas.ActualHeight - text.MinHeight) && ct1.TranslateY + e.Delta.Translation.Y >= 500)
ct1.TranslateY -= e.Delta.Translation.Y;
}
// DRag and drop the images on canvas
imageitem.ManipulationMode = ManipulationModes.All;
imageitem.ManipulationDelta += Drag_ManipulationDelta;
CompositeTransform ct = new CompositeTransform();
imageitem.RenderTransform = ct;
親愛的先生這本書能解決我的這個我的形象一半的問題是縮小而不是放大項。 –
是否可以在鼠標滾輪上縮小和放大圖像 –
是的。我會更新答案 – Archana