using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using wpf_Rectangles._UserControls;
namespace wpf_Rectangles
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
#region mouse dragging
//-------------<
MouseMove() >-------------
public Boolean isSizing = false;
public int sizing_EdgeType = 0;
public double sizing_Offset_X = 0;
public double sizing_Offset_Y = 0;
public UcPanel sizing_Panel = null;
public Border sizing_Edge = null;
enum EdgeTypes
{
TopMove = 0,
TopLeft = 1,
TopRight = 2,
BottomLeft = 3,
BottomRight = 4
}
public void CanvasMain_MouseUp(object sender, MouseButtonEventArgs e)
{
//-------------< MouseUp()
>-------------
if (isSizing)
{
//--< reset >--
isSizing = false;
sizing_EdgeType = -1;
sizing_Offset_X = 0;
sizing_Offset_Y = 0;
sizing_Panel = null;
sizing_Edge = null;
//--</ reset >--
}
//-------------</ MouseUp()
>-------------
}
private void CanvasMain_MouseMove(object sender, MouseEventArgs e)
{
//------------< MouseMove()
>------------
if (isSizing == true) set_Sizing(sender, e);
//-------------</ MouseMove()
>------------
}
private void set_Sizing(object sender, MouseEventArgs e)
{
//-------------<
sizing_Cols_And_Rows() >-------------
if (isSizing == false) return;
//< check >
if (sizing_EdgeType < 0) return;
if (sizing_Panel == null) return;
//</ check >
if (e.LeftButton != MouseButtonState.Pressed)
{
isSizing = false;
}
else
{
//------< MouseButtonState.Pressed
>------
//< mouse position >
Point mouse_point = e.GetPosition(this);
double mouse_x = mouse_point.X;
double mouse_y = mouse_point.Y;
//</ mouse position >
//--< get Position >--
Point position = this.TranslatePoint(new Point(0, 0), sizing_Panel );
double pos_X = -position.X;
double pos_Y = -position.Y;
//--</ get Position >--
////--< get Offset >--
//Point offset =
e.GetPosition(sizing_Edge);
//double offset_X = offset.X;
//double offset_Y = offset.Y;
////--</ get Offset >--
double diff_X = (pos_X - mouse_x);
double diff_Y = (pos_Y - mouse_y);
if (sizing_EdgeType == (int)EdgeTypes.TopMove)
{
//----< sizing Move >----
double new_Left = mouse_x - sizing_Offset_X ;
double new_Top = mouse_y - sizing_Offset_Y;
//< set >
if (new_Left > 0) Canvas.SetLeft(sizing_Panel,
new_Left);
if (new_Top > 0) Canvas.SetTop(sizing_Panel, new_Top);
//</ set >
//----</ sizing Move
>----
}
else
{
//-------------< sizing
>--------------
if ((sizing_EdgeType == (int)EdgeTypes.TopLeft) || (sizing_EdgeType == (int)EdgeTypes.BottomLeft))
{
//----< sizing Left >----
double new_Left = mouse_x ;
double new_Width = (sizing_Panel.ActualWidth)
+ diff_X;
//< set Left >
if (new_Left > 0) Canvas.SetLeft(sizing_Panel,
new_Left);
//</ set Left >
//< set width >
if (new_Width > 0) sizing_Panel.Width =
new_Width;
//</ set width >
//----</ sizing Left
>----
}
if ((sizing_EdgeType == (int)EdgeTypes.TopLeft) || (sizing_EdgeType == (int)EdgeTypes.TopRight ))
{
//----< sizing Top >----
double new_Top = mouse_y;
double new_Height =
(sizing_Panel.ActualHeight) + diff_Y;
//< set Left >
if (new_Top > 0) Canvas.SetTop(sizing_Panel, new_Top);
//</ set Left >
//< set width >
if (new_Height > 0)
sizing_Panel.Height = new_Height;
//</ set width >
//----</ sizing Top >----
}
if ((sizing_EdgeType == (int)EdgeTypes.TopRight) || (sizing_EdgeType == (int)EdgeTypes.BottomRight))
{
//----< sizing Right
>----
double new_Width = mouse_x-pos_X ;
//< set width >
if (new_Width > 0) sizing_Panel.Width =
new_Width;
//</ set width >
//----</ sizing Right
>----
}
if ((sizing_EdgeType == (int)EdgeTypes.BottomLeft) || (sizing_EdgeType == (int)EdgeTypes.BottomRight))
{
//----< sizing Bottom
>----
double new_Height = mouse_y - pos_Y;
//< set width >
if (new_Height > 0)
sizing_Panel.Height = new_Height ;
//</ set width >
//----</ sizing Bottom
>----
}
//-------------</ sizing
>--------------
}
//------</ MouseButtonState.Pressed
>------
}
//-------------</
sizing_Cols_And_Rows() >-------------
}
#endregion /mouse dragging
}
}
|