我在C Sharp中爲簡單的Surface Table應用程序編程。如何在Surface應用程序中移動圖片(智能表,C Sharp .Net 4)
我有一個畫布和圖像幀:
<Canvas Name="InputCanvas"
Background="SeaGreen"
TouchDown="InputCanvas_TouchDown"
TouchMove="InputCanvas_TouchMove"
TouchUp="InputCanvas_TouchUp"
MouseLeftButtonDown="InputCanvas_MouseLeftButtonDown"
MouseMove="InputCanvas_MouseMove"
MouseLeftButtonUp="InputCanvas_MouseLeftButtonUp">
<Image Canvas.Left="0" Canvas.Top="0"
Height="610" Width="1590"
Name="imgKeyboard" Stretch="None" />
</Canvas>
當我把圖片中的「imgKeyboard」像這裏面:
BitmapImage kbdBitmap = new BitmapImage();
kbdBitmap.BeginInit();
kbdBitmap.UriSource = new Uri(BaseUriHelper.GetBaseUri(this), "Resources/keyboard_1x.png");
kbdBitmap.EndInit();
imgKeyboard.Source = kbdBitmap;
鍵盤畫面將出現在該中心圖片(圖片比畫布小得多)
當然,我可以通過更改'Canvas.Left','Canvas.Top',等等來移動XML中的鍵盤圖片,例如
但我想動態地在C Sharp代碼中移動鍵盤圖片。
我發現MSDN上一些代碼,但他們似乎是無關緊要的:
private void DrawImagePoint(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create Point for upper-left corner of image.
Point ulCorner = new Point(100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
我不知道往哪裏放這些代碼,我不能在我的表面代碼中使用這些類。
任何人都可以給我一些建議嗎?謝謝:)
謝謝!你的建議非常有幫助。 –
謝謝@ ZhenLi,如果這個答案解決了你的問題,請將其標記爲答案。 – Clint