15-01-14, 04:07 PM
بسم الله الرحمن الرحيم
الصلاة و السلام على سيدنا محمد و على آله و صحبه و سلم
السلام عليكم و رحمة الله و بركاته
كيف الشباب؟ إن شاء الله بخير ...
عندي كود غير مفهوم بالنسبة لي, أتمنى من أصحاب الخبرة شرح الكود التالي:
ومشكوووووور مقدماً على جهودكم
السلام عليكم
الصلاة و السلام على سيدنا محمد و على آله و صحبه و سلم
السلام عليكم و رحمة الله و بركاته
كيف الشباب؟ إن شاء الله بخير ...
عندي كود غير مفهوم بالنسبة لي, أتمنى من أصحاب الخبرة شرح الكود التالي:
PHP كود :
public partial class MainWindow : Window
{
bool isMouseCaptured = false;
double mouseVerticalPosition = 0;
double mouseHorizontalPosition = 0;
public MainWindow()
{
InitializeComponent();
InitializeControlEvents();
InitializeControls();
}
void InitializeControls()
{
}
void InitializeControlEvents()
{
this.SizeChanged += new SizeChangedEventHandler(MainWindow_SizeChanged);
this.DragBar.MouseDown += new MouseButtonEventHandler(DragBar_MouseDown);
this.DragBar.MouseMove += new MouseEventHandler(DragBar_MouseMove);
this.DragBar.MouseUp += new MouseButtonEventHandler(DragBar_MouseUp);
}
void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
DragBar.Width = SystemParameters.FullPrimaryScreenWidth;
MainContent.Width = SystemParameters.FullPrimaryScreenWidth;
MainContent.Height = this.Height;
}
void DragBar_MouseUp(object sender, MouseButtonEventArgs e)
{
ScaleTransformAnimation(MainContent, 0.3, 1, 0.5, 0, 150);
ScaleTransformAnimation(DragBar, 0.3, 1, 0.5, 0, 150);
isMouseCaptured = false;
DragBar.ReleaseMouseCapture();
mouseVerticalPosition = -1;
mouseHorizontalPosition = -1;
Canvas.SetTop(DragBar, 0);
Canvas.SetLeft(DragBar, 0);
Canvas.SetTop(MainContent, 0);
Canvas.SetLeft(MainContent, 0);
}
void DragBar_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseCaptured)
{
// Calculate the current position of the object.
double deltaV = e.GetPosition(null).Y - mouseVerticalPosition;
double deltaH = e.GetPosition(null).X - mouseHorizontalPosition;
double newTop = deltaV + (double)DragBar.GetValue(Canvas.TopProperty);
double newLeft = deltaH + (double)DragBar.GetValue(Canvas.LeftProperty);
// Set new position of object.
DragBar.SetValue(Canvas.TopProperty, newTop);
DragBar.SetValue(Canvas.LeftProperty, newLeft);
MainContent.SetValue(Canvas.TopProperty, newTop);
MainContent.SetValue(Canvas.LeftProperty, newLeft);
int distance = Distance2D(0, Convert.ToInt32(MainContent.Height), 0, Convert.ToInt32(mouseVerticalPosition));
if (distance < 30)
{
this.Close();
}
// Update position global variables.
mouseVerticalPosition = e.GetPosition(null).Y;
mouseHorizontalPosition = e.GetPosition(null).X;
}
}
void DragBar_MouseDown(object sender, MouseButtonEventArgs e)
{
mouseVerticalPosition = e.GetPosition(null).Y;
mouseHorizontalPosition = e.GetPosition(null).X;
isMouseCaptured = true;
DragBar.CaptureMouse();
ScaleTransformAnimation(MainContent, 1, 0.3, 0.5, 0, 150);
ScaleTransformAnimation(DragBar, 1, 0.3, 0.5, 0, 150);
}
void ScaleTransformAnimation(UIElement element, double fromValue, double toValue, double centerX, double centerY, int duration_ms)
{
ScaleTransform scale_trans = new ScaleTransform()
{
ScaleX = toValue,
ScaleY = toValue
};
DoubleAnimation danim = new DoubleAnimation()
{
From = fromValue,
Duration = TimeSpan.FromMilliseconds(duration_ms)
};
element.RenderTransformOrigin = new Point(centerX, centerY);
element.RenderTransform = scale_trans;
scale_trans.BeginAnimation(ScaleTransform.ScaleXProperty, danim);
scale_trans.BeginAnimation(ScaleTransform.ScaleYProperty, danim);
}
public int Distance2D(int x1, int y1, int x2, int y2)
{
//Our end result
int result = 0;
//Take x2-x1, then square it
double part1 = Math.Pow((x2 - x1), 2);
//Take y2-y1, then sqaure it
double part2 = Math.Pow((y2 - y1), 2);
//Add both of the parts together
double underRadical = part1 + part2;
//Get the square root of the parts
result = (int)Math.Sqrt(underRadical);
//Return our result
return result;
}
}
ومشكوووووور مقدماً على جهودكم
السلام عليكم