一般點擊 Window的標題列,接著滑鼠移動,視窗自然而然就會跟著動,但是在 Window的 WindowStyle設為 None時,Window的標題列不見囉

這時該怎麼移動 Window呢?

作法是添加 MouseLeftButtonDown再加 MouseMove 這兩個事件去處理滑鼠移動數及改變 Window的 Top和 Left的值。

首先,先宣告一個全域 Point,程式碼如下:

private Point _startPoint;

在 Constructor或 Window_Load處添加 MouseButtonEventHandler和 MouseEventHandler,程式碼如下:

this.PreviewMouseLeftButtonDown += 
        new MouseButtonEventHandler(Window_PreviewMouseLeftButtonDown);
this.PreviewMouseMove += new MouseEventHandler(Window_PreviewMouseMove);

接著,實作 Window_PreviewMouseLeftButtonDown和 Window_PreviewMouseMove,程式碼如下:

private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _startPoint = e.GetPosition(null);
}

private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        Point position = e.GetPosition(null);
        Top += position.Y - _startPoint.Y;
        Left += position.X - _startPoint.X;
    }
}

 

以上的是拖移 Window的程式碼,那接下來是有關 Drag&Drop的東西

也就是你可以把元件A拖拉到元件B,正常來說這是禁止的,如何讓他可以啟用呢?

首先,你要先將元件A的 AllowDrop設為 True。

接下來的動作很像上面的程式碼,例如宣告一個全域 Point和在 Constructor或 Window_Load處添加 MouseButtonEventHandler和 MouseEventHandler,不過這次要指定這兩個事件是元件A的。

this.[元件A].PreviewMouseLeftButtonDown += 
        new MouseButtonEventHandler([元件A]_PreviewMouseLeftButtonDown);
this.[元件A].PreviewMouseMove += new MouseEventHandler([元件A]_PreviewMouseMove);

接著一樣,實作 [元件A]_PreviewMouseLeftButtonDown和 [元件A]_PreviewMouseMove,[元件A]_PreviewMouseLeftButtonDown的內容和上面的一樣,[元件A]_PreviewMouseMove就有點不同了,程式碼如下:

private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _startPoint = e.GetPosition(null);
}

private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
        if (e.LeftButton == MouseButtonState.Pressed)
        {
                Point position = e.GetPosition(null);

                if (Math.Abs(position.X - _startPoint.X) > 
                                SystemParameters.MinimumHorizontalDragDistance ||
                        Math.Abs(position.Y - _startPoint.Y) > 
                                SystemParameters.MinimumVerticalDragDistance)
                {
                        DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), 
                                "Drag&Drop");
                        DragDropEffects de = DragDrop.DoDragDrop([元件A], data, DragDropEffects.Move);
                }
        } 
}

DataObject 就是拖拉到元件B時,元件B獲得的東西,在此宣告為字串 "Drag&Drop"

參考至 http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-wpf-explained-end-to-end.aspx

膩撐 發表在 痞客邦 留言(1) 人氣()

於WPF視窗程式內加入報表(ReportViewer),再將資料庫的資料輸出成報表顯示出來

膩撐 發表在 痞客邦 留言(0) 人氣()

reference: http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_step_by_step_guide/s1-q-and-a-root-passwd.html

Forgotten root Password

  1. At the boot loader menu, use the arrow keys to highlight the installation you want to edit and type [A] to enter into append mode.

  2. You are presented with a prompt that looks similar to the following:

    grub append> ro root=LABEL=/
    
  3. Press the Spacebar once to add a blank space, then add the word single to tell GRUB to boot into single-user Linux mode. The result should look like the following:

    ro root=LABEL=/ single
    
  4. Press [Enter] and GRUB will boot single-user Linux mode. After it finishes loading, you will be presented with a shell prompt similar to the following:

    sh-2.05b#
    
  5. You can now change the root password by typing

    passwd root
    

    You will be asked to re-type the password for verification. Once you are finished, the password will be changed. You can then reboot by typing reboot at the prompt; then you can log in to root as you normally would.

膩撐 發表在 痞客邦 留言(0) 人氣()

1 234