Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


CSharp Programming

CSharp > Code Examples

Cast event sender to a control

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Cast event sender to a control <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="MyNameSpace.IncludeApplicationDefinition.MyWindow" Title="Include Application Definition" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize"> <Button HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1.5in" Click="ButtonOnClick"> Click </Button> </Window> //File:Window.xaml.cs using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace MyNameSpace.IncludeApplicationDefinition { public partial class MyWindow : Window { public MyWindow() { InitializeComponent(); } void ButtonOnClick(object sender, RoutedEventArgs args) { Button btn = sender as Button; MessageBox.Show(btn.Content + "'clicked."); } } }