wpf 透明窗口拉伸

<Grid>
        <Rectangle Cursor="ScrollWE" Fill="Transparent" 
                   Width="5" 
                   VerticalAlignment="Stretch" 
                   HorizontalAlignment="Right"
                   MouseLeftButtonDown="window_initiateWiden"
                   MouseLeftButtonUp="window_endWiden"
                   MouseMove="window_Widen"></Rectangle>
        
        <Rectangle Cursor="ScrollNS" Fill="Transparent" 
                   Height="5" 
                   VerticalAlignment="Bottom" 
                   HorizontalAlignment="Stretch"
                   MouseLeftButtonDown="window_initiateHeight"
                   MouseLeftButtonUp="window_endHeight"
                   MouseMove="window_Height"></Rectangle>
</Grid>


 

bool isWiden = false;
        private void window_initiateWiden(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = true;
        }
        private void window_endWiden(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = false;

            // Make sure capture is released.
            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }

        private void window_Widen(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isWiden)
            {
                rect.CaptureMouse();
                double newWidth = e.GetPosition(this).X + 5;
                if (newWidth > 0) this.Width = newWidth;
            }
        }


        bool isHeight = false;
        private void window_initiateHeight(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isHeight = true;
        }
        private void window_endHeight(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isHeight = false;

            // Make sure capture is released.
            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }

        private void window_Height(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isHeight)
            {
                rect.CaptureMouse();
                double newHeight = e.GetPosition(this).Y + 5;
                if (newHeight > 0) this.Height = newHeight;
            }
        }


 

你可能感兴趣的:(wpf 透明窗口拉伸)