久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='NXpND'></tfoot>
  • <i id='NXpND'><tr id='NXpND'><dt id='NXpND'><q id='NXpND'><span id='NXpND'><b id='NXpND'><form id='NXpND'><ins id='NXpND'></ins><ul id='NXpND'></ul><sub id='NXpND'></sub></form><legend id='NXpND'></legend><bdo id='NXpND'><pre id='NXpND'><center id='NXpND'></center></pre></bdo></b><th id='NXpND'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NXpND'><tfoot id='NXpND'></tfoot><dl id='NXpND'><fieldset id='NXpND'></fieldset></dl></div>
      <bdo id='NXpND'></bdo><ul id='NXpND'></ul>

  • <legend id='NXpND'><style id='NXpND'><dir id='NXpND'><q id='NXpND'></q></dir></style></legend>

    <small id='NXpND'></small><noframes id='NXpND'>

        運行時在窗體上拖動控件

        Dragging Controls on Form at runtime(運行時在窗體上拖動控件)
        <legend id='hlzG4'><style id='hlzG4'><dir id='hlzG4'><q id='hlzG4'></q></dir></style></legend>

              <tbody id='hlzG4'></tbody>
              <bdo id='hlzG4'></bdo><ul id='hlzG4'></ul>

              <small id='hlzG4'></small><noframes id='hlzG4'>

            • <tfoot id='hlzG4'></tfoot>

                <i id='hlzG4'><tr id='hlzG4'><dt id='hlzG4'><q id='hlzG4'><span id='hlzG4'><b id='hlzG4'><form id='hlzG4'><ins id='hlzG4'></ins><ul id='hlzG4'></ul><sub id='hlzG4'></sub></form><legend id='hlzG4'></legend><bdo id='hlzG4'><pre id='hlzG4'><center id='hlzG4'></center></pre></bdo></b><th id='hlzG4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hlzG4'><tfoot id='hlzG4'></tfoot><dl id='hlzG4'><fieldset id='hlzG4'></fieldset></dl></div>
                  本文介紹了運行時在窗體上拖動控件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我剛剛開始使用 WPF.但我正在嘗試添加我的代碼(來自 Winforms),使用戶能夠在運行時將任何控件拖動到他們希望的任何位置.但我似乎無法獲得鼠標的當前位置......嗯?鼠標沒有位置?:(

                  I've just started using WPF. But I'm trying to add my code that (from Winforms) enables the user to drag any control whereever they wish at runtime. But I can't seem to get the current Location of the mouse... Eh? There is no Location for Mouse? :(

                  推薦答案

                  在鼠標事件中可以使用 e.GetPosition 獲取當前鼠標位置.此函數可以提供相對于特定元素的鼠標位置,或者您可以只傳遞 null.

                  In the Mouse event you can use e.GetPosition to get the current mouse position. This function can provide the mouse position relative to a specific element or you can just pass null.

                  這是一個非常簡單的例子,沒有命中測試或任何東西,只是一個可以拖動的按鈕.我使用了一個畫布來保持它的簡短,但您可能會更好地使用轉換并將控件轉換到所需的位置.

                  Here is a very simple example, no hit testing or anything, just a button that you can drag around. And I used a canvas to keep it short, but you would probably do better to use a transform and translate the control to the desired position.

                  <Window x:Class="WpfApplication1.MainWindow"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          Title="MainWindow" Height="350" Width="525">
                      <Canvas PreviewMouseLeftButtonDown="Canvas_PreviewMouseLeftButtonDown" 
                              PreviewMouseMove="Canvas_PreviewMouseMove" 
                              PreviewMouseLeftButtonUp="Canvas_PreviewMouseLeftButtonUp">
                          <Button Name="dragButton" Width="80" Height="21" Canvas.Left="50" Canvas.Top="10">Drag Me!</Button>
                      </Canvas>
                  </Window>
                  


                  using System;
                  using System.Windows;
                  using System.Windows.Controls;
                  using System.Windows.Input;
                  
                  namespace WpfApplication1
                  {
                    public partial class MainWindow : Window
                    {
                      public MainWindow()
                      {
                        InitializeComponent();      
                      }    
                  
                      private Point _startPoint;
                      private bool _dragging = false;
                  
                      private void Canvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
                      {         
                        if (dragButton.CaptureMouse())
                        {        
                          _startPoint = e.GetPosition(null);
                          _dragging = true;        
                        }
                      }
                  
                      private void Canvas_PreviewMouseMove(object sender, MouseEventArgs e)
                      {
                        if (_dragging)
                        {        
                          Point newPoint = e.GetPosition(null);
                          double dx = newPoint.X - _startPoint.X;
                          double dy = newPoint.Y - _startPoint.Y;
                  
                          Canvas.SetLeft(dragButton, Canvas.GetLeft(dragButton) + dx);
                          Canvas.SetTop(dragButton, Canvas.GetTop(dragButton) + dy);
                          _startPoint = newPoint;
                        }
                      }
                  
                      private void Canvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
                      {
                        if (_dragging)
                        {        
                          _dragging = false;
                          dragButton.ReleaseMouseCapture();
                        }
                      }    
                    }
                  }
                  

                  這篇關于運行時在窗體上拖動控件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)
                      • <bdo id='C4VTJ'></bdo><ul id='C4VTJ'></ul>
                        <i id='C4VTJ'><tr id='C4VTJ'><dt id='C4VTJ'><q id='C4VTJ'><span id='C4VTJ'><b id='C4VTJ'><form id='C4VTJ'><ins id='C4VTJ'></ins><ul id='C4VTJ'></ul><sub id='C4VTJ'></sub></form><legend id='C4VTJ'></legend><bdo id='C4VTJ'><pre id='C4VTJ'><center id='C4VTJ'></center></pre></bdo></b><th id='C4VTJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='C4VTJ'><tfoot id='C4VTJ'></tfoot><dl id='C4VTJ'><fieldset id='C4VTJ'></fieldset></dl></div>

                        <small id='C4VTJ'></small><noframes id='C4VTJ'>

                        1. <tfoot id='C4VTJ'></tfoot>

                          <legend id='C4VTJ'><style id='C4VTJ'><dir id='C4VTJ'><q id='C4VTJ'></q></dir></style></legend>
                              <tbody id='C4VTJ'></tbody>
                            主站蜘蛛池模板: 在线少妇| 亚洲成人黄色 | 日韩欧美自拍 | 伊人久久综合 | 黑人精品xxx一区一二区 | 张津瑜国内精品www在线 | 欧美一区视频 | 欧美一区二区三区在线观看 | 青青草国产成人av片免费 | 特黄一级片 | 狠狠的干 | 狠狠婷婷 | 超碰人人射| 97超碰免费| 一区二区在线看 | 精久久久久 | 在线观看的av | 日韩在线毛片 | 可以在线观看的av | 欧美色综合网 | 日韩欧美一区在线 | 黄色一及片 | 欧美专区第一页 | 日韩av不卡在线 | 亚洲国产天堂 | 欧美专区第一页 | 一区二区三区高清 | 中文字幕一区二区三区在线观看 | 成人玩具h视频 | 看国产毛片 | 免费v片在线观看 | 欧美日韩在线精品 | 久久久久久久网 | 久久久久久网 | 99精品久久久 | 羞羞在线 | 黄色小视频免费观看 | 精品视频国产 | 一区二区网站 | 国产一区精品在线 | japanese极品丰满少妇 |