Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi CP,
I am trying to create a On Screen / Virtual keyboard, and I would like to do so in WPF..I have craeted my layout etc, and I have managed to get my onscreen Keyboard working..The problem I have is that when I Click and Drag My Virtual keyboard its not coming along with the mouse..It just got dragged after I release the mouse click..Is there a way I can clear up this problem,in the same way that the MS OSK works?

Note:
Later I will use this project in Touch Screen..So i don't need to use Mouse Click Events..

Here is my Sample Code,,

C#
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex,
                                                  IntPtr dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
public static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);


public Window1()
{
    InitializeComponent();
    this.Topmost = true;
}


private void Window_Loaded(object sender, RoutedEventArgs e)
{
    IntPtr HWND = new WindowInteropHelper(this).Handle;
    const int GWL_EXSTYLE = (-20);

    GetWindowLong(HWND, GWL_EXSTYLE);
    SetWindowLong(HWND, GWL_EXSTYLE, (IntPtr)(0x8000000));

}

private void AllButton_Click(object sender, RoutedEventArgs e)
{
    String tempstring = "";

    try
    {
        e.Handled = true;
        tempstring = ((Button)sender).CommandParameter.ToString();

        System.Windows.Forms.SendKeys.SendWait(tempstring);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.ToString());
    }
}
Posted

In the MouseLeftButtonDown event you just need to put this.DragMove(). Something like this

C#
private void Login_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }


This way you can drag the form anywhere with the mouse.

Hope this helps
 
Share this answer
 
Comments
Ahn_7 29-Aug-11 5:09am    
See the Note Wayne..He doesn't need any Mouse Click Events..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900