如何在没有明确提及他的名字的情况下访问事件函数的变量? [英] How to access variable of the event function without explicit mention his name?
本文介绍了如何在没有明确提及他的名字的情况下访问事件函数的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在广场并运行他的事件功能,
如何在不明确转向变量的情况下访问其颜色?
Suppose I am in the square and I run his event function,
How can I access to its color without turning to the variable explicitly?
private void recblack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{ <--! i don't want to mention his name (recblack)>
colorpiker.Fill = recblack.Fill;
}
推荐答案
试试这个:
Try this:
private void recblack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
WhatEverControlTypeItIs rb = sender as WhatEverControlTypeItIs;
if (rb != null)
{
colorpiker.Fill = rb.Fill;
}
}
所以如果recBlack是一个Button:
So if recBlack was a Button:
private void recblack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Button but = sender as Button;
if (but != null)
{
string s = but.Text;
}
}
等等
这篇关于如何在没有明确提及他的名字的情况下访问事件函数的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文