تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] WPF Code
#1
بسم الله الرحمن الرحيم
الصلاة و السلام على سيدنا محمد و على آله و صحبه و سلم

السلام عليكم و رحمة الله و بركاته

كيف الشباب؟ إن شاء الله بخير ...
عندي كود غير مفهوم بالنسبة لي, أتمنى من أصحاب الخبرة شرح الكود التالي:

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 senderSizeChangedEventArgs e)
        {
            
DragBar.Width SystemParameters.FullPrimaryScreenWidth;

            
MainContent.Width SystemParameters.FullPrimaryScreenWidth;
            
MainContent.Height this.Height;
        }

        
void DragBar_MouseUp(object senderMouseButtonEventArgs e)
        {
            
ScaleTransformAnimation(MainContent0.310.50150);
            
ScaleTransformAnimation(DragBar0.310.50150);

            
isMouseCaptured false;
            
DragBar.ReleaseMouseCapture();
            
mouseVerticalPosition = -1;
            
mouseHorizontalPosition = -1;

            
Canvas.SetTop(DragBar0);
            
Canvas.SetLeft(DragBar0);
            
Canvas.SetTop(MainContent0);
            
Canvas.SetLeft(MainContent0);
        }

        
void DragBar_MouseMove(object senderMouseEventArgs e)
        {
            if (
isMouseCaptured)
            {
                
// Calculate the current position of the object.
                
double deltaV e.GetPosition(null).mouseVerticalPosition;
                
double deltaH e.GetPosition(null).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.TopPropertynewTop);
                
DragBar.SetValue(Canvas.LeftPropertynewLeft);

                
MainContent.SetValue(Canvas.TopPropertynewTop);
                
MainContent.SetValue(Canvas.LeftPropertynewLeft);

                
int distance Distance2D(0Convert.ToInt32(MainContent.Height), 0Convert.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 senderMouseButtonEventArgs e)
        {
            
mouseVerticalPosition e.GetPosition(null).Y;
            
mouseHorizontalPosition e.GetPosition(null).X;
            
isMouseCaptured true;
            
DragBar.CaptureMouse();

            
ScaleTransformAnimation(MainContent10.30.50150);
            
ScaleTransformAnimation(DragBar10.30.50150);
        }

        
void ScaleTransformAnimation(UIElement elementdouble fromValuedouble toValuedouble centerXdouble centerYint 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(centerXcenterY);
            
element.RenderTransform scale_trans;

            
scale_trans.BeginAnimation(ScaleTransform.ScaleXPropertydanim);
            
scale_trans.BeginAnimation(ScaleTransform.ScaleYPropertydanim);
        }

        public 
int Distance2D(int x1int y1int x2int 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;
        }
    } 

ومشكوووووور مقدماً على جهودكم



السلام عليكم
الرد }}}
تم الشكر بواسطة:
#2
الكود واضح انه لتحريك بعض الادوات
عززرا رديت علي عجل
microsoft partner
Team administrator
MCPD,MCITP,OCP,MP,MCC
Xprema Systems
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  طلب برنامج Code Builder v4.2 maxruined 0 1,340 27-07-21, 11:33 AM
آخر رد: maxruined
  [C#.NET] vb.net code ashrafhayek 1 1,095 09-10-20, 04:16 PM
آخر رد: asemshahen5
  خطأ not all code paths return a value فارس الأصيل 1 1,033 16-05-20, 10:02 PM
آخر رد: khodor1985
  [C#.NET] Ascii code الخاص بالأزرار 739906433 1 1,776 19-11-18, 08:44 AM
آخر رد: elgokr
  عندي source code C# adel500 2 1,994 25-10-17, 02:21 PM
آخر رد: adel500
  Hide your app Code أبو عمر 0 1,600 21-09-15, 03:26 AM
آخر رد: أبو عمر
Exclamation [C#.NET] code amx 1 2,145 21-01-15, 12:30 AM
آخر رد: المبرمج الطموح88

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم