WPF 控件【B】Border (一) 设置Border 不一样的四条边+不一样的四个角的弧度

        <Border Grid.Column="1" BorderThickness="0,1,1,1" BorderBrush="#FFABADB3" CornerRadius="0,1,1,0">
                            <ToggleButton Style="{StaticResource ComboxStyleBtn38x40}" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Release"></ToggleButton>
                        </Border>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您可以通过在Border的MouseLeftButtonDown、MouseLeftButtonUp和MouseMove事件上添加事件处理程序来实现拖动四条边改变大小的功能。具体实现方法如下: 1. 在XAML文件中,设置Border的边框样式和初始大小: ``` <Border BorderThickness="1" BorderBrush="Black" Width="100" Height="100" MouseLeftButtonDown="Border_MouseLeftButtonDown" MouseLeftButtonUp="Border_MouseLeftButtonUp" MouseMove="Border_MouseMove"> <!-- Border中的内容 --> </Border> ``` 2. 在代码文件中,定义以下变量: ``` private bool isResizing = false; // 标记是否正在改变大小 private Point lastMousePosition; // 记录上一次鼠标位置 ``` 3. 添加事件处理程序: ``` private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // 点击Border时,标记为正在改变大小,并记录鼠标位置 isResizing = true; lastMousePosition = e.GetPosition(this); } private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { // 松开鼠标时,标记为不再改变大小 isResizing = false; } private void Border_MouseMove(object sender, MouseEventArgs e) { // 如果正在改变大小,根据鼠标位置计算新的大小 if (isResizing) { Point currentMousePosition = e.GetPosition(this); double horizontalChange = currentMousePosition.X - lastMousePosition.X; double verticalChange = currentMousePosition.Y - lastMousePosition.Y; double newWidth = Math.Max(this.Border.ActualWidth + horizontalChange, 0); double newHeight = Math.Max(this.Border.ActualHeight + verticalChange, 0); this.Border.Width = newWidth; this.Border.Height = newHeight; lastMousePosition = currentMousePosition; } } ``` 这样,就可以实现通过拖动四条边改变Border大小的功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值