Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF Move the window

I have added the following parameters to my Window:

WindowStyle="None"
WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
ResizeMode="NoResize" Background="Transparent" 

And now I can't move the Window, so I have added the following part of code to my Window:

#region Window: Moving

private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    DragMove();
}

#endregion

Also I must specify that my XAML code in my Window is the following (the Window look like the Polygon):

<Window Title="New Science"
    Height="588" Width="760" MinHeight="360" MinWidth="360"
    WindowStyle="None" WindowStartupLocation="CenterScreen"
    AllowsTransparency="True"
    ResizeMode="NoResize" Background="Transparent"
    xmlns:my="clr-namespace:Bourlesque.Lib.Windows.Media;assembly=Bourlesque.Lib.Windows.Media">
    <Grid>
        <my:UniPolygon DefaultRadiusIn="10" DefaultRadiusOut="10" Fill="#FF92C2F2" Name="m_tPlgOuter" Offset="0" Points="         0;26;;         10;19;10;;         10;0;;         265;0;20;;         290;20;20;;          -60,1;20;3;;         -60,1;5;10;;         -40,1;5;10;;         -40,1;20;2.5;;          -35,1;20;2.5;;         -35,1;5;10;;         -15,1;5;10;;         -15,1;20;3;;          0,1;20;;         0,1;0,1;;         0;0,1;;       " Stretch="None" Stroke="#FF535353" StrokeThickness="0.1" />
    </Grid>
</Window>

I would like to know what should I do to make the Window change it's position on mouse drag and what to add to resize the window with the condition that the controls and other things I will add will resize too(I have found this code to resize and I would like to know if is good here).

like image 457
user2194683 Avatar asked May 17 '13 12:05

user2194683


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

I used the event MouseDown:

<Window .....
     MouseDown="Window_MouseDown"  >

with this code:

  private void Window_MouseDown(object sender, MouseButtonEventArgs e)
  {
     if(e.ChangedButton == MouseButton.Left)
        this.DragMove();
  }
like image 169
Sandro Z. Avatar answered Oct 02 '22 19:10

Sandro Z.


Found a example: http://cloudstore.blogspot.com.br/2008/06/moving-wpf-window-with-windowstyle-of.html

Anyway, to move a Window in WinForms I used in a project the following code, can be useful if you are having problems:

private bool clicado = false;
private Point lm = new Point();
void PnMouseDown(object sender, MouseEventArgs e)
{
    clicado = true;
    this.lm = MousePosition;
}

void PnMouseUp(object sender, MouseEventArgs e)
{
    clicado = false;
}

void PnMouseMove(object sender, MouseEventArgs e)
{
    if(clicado)
    {
        this.Left += (MousePosition.X - this.lm.X);
        this.Top += (MousePosition.Y - this.lm.Y);
        this.lm = MousePosition;
    }
}
like image 35
gariel Avatar answered Oct 02 '22 19:10

gariel