Button myButton = new Button(); myButton.Content = "Click me!"; myButton.Width = 75; myButton.Height = 30;
private void MyButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Button clicked!"); }This code creates a new button control with the text "Click me!" and attaches a click event handler to it. When the button is clicked, the MyButton_Click method is called, which displays a message box with the text "Button clicked!". Package library: System.Windows.Controls namespace in the WPF library.