这样子产生的边框怎么添加方法或者怎么样才能在方法里被区分
时间: 2024-03-06 13:50:40 浏览: 25
你可以在CustomFont_MouseLeftButtonDown方法中加入一些逻辑,来区分当前是哪个控件触发了这个方法。一种简单的方式是通过sender参数来获取当前触发事件的控件,然后使用控件的Name属性或者Tag属性来进行区分。例如,你可以给每个控件设置一个不同的Name属性值或者Tag属性值,然后在CustomFont_MouseLeftButtonDown方法中使用if语句来判断当前触发事件的是哪个控件,从而进行不同的处理。下面是一个示例代码:
```
private void CustomFont_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 获取当前触发事件的控件
CustomFont customFont = sender as CustomFont;
if (customFont == null)
{
return;
}
// 根据控件的Name属性或者Tag属性来区分不同的控件
if (customFont.Name == "Control1")
{
// 处理控件1的边框
customFont.BorderBrush = new SolidColorBrush(Colors.Black);
customFont.BorderThickness = new Thickness(1);
}
else if (customFont.Name == "Control2")
{
// 处理控件2的边框
customFont.BorderBrush = new SolidColorBrush(Colors.Red);
customFont.BorderThickness = new Thickness(2);
}
// ... 添加更多控件的处理逻辑
}
```
在上面的示例代码中,我们首先将sender参数转换成CustomFont类型的对象,然后使用if语句根据控件的Name属性或者Tag属性来区分不同的控件,从而进行不同的处理。你可以根据你的实际需求来修改上面的示例代码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)