How do I change the shape of the button to an ellipse?

The button’s shape can be changed to any shape by applying the control template to a button. The following code snippet is used to change the shape of a button to an ellipse. [XAML] <ControlTemplate x:Key=’Temp1′ TargetType='{x:Type Button}’> <Grid> <Ellipse x:Name=’Ell’ Width='{TemplateBinding Width}’ Height=’50’> <Ellipse.Fill> <LinearGradientBrush StartPoint=’0,0.5′ EndPoint=’1,0.5′> <GradientStop Offset=’0.3′ Color=’YellowGreen’/> <GradientStop Offset=’1′ Color=’Green’/> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <Viewbox> <ContentControl Margin=’10’ Content='{TemplateBinding Content}’ FontSize=’11’ HorizontalContentAlignment=’Center’ Foreground=’AntiqueWhite’/> </Viewbox> </Grid> </ControlTemplate> <Button Name=’Button1′ Template='{StaticResource Temp1}’ Height=’50’ Width=’80’>Templated Button</Button>

How do I create custom layout for StatusBar items?

StatusBar uses a DockPanel as an item template and docks all the items in the control to the left except for the last item. The last item takes the rest of the space in the statusbar. To have a custom layout for the statusbar control, you can change the DockPanel to a StackPanel, WrapPanel etc. You can also align the items in the statusbar using the DockPanel.Dock property for each statusbar item. The following lines of code are used to change the alignment of the statusbar items. [XAML] <StatusBar Height=’30’ VerticalAlignment=’Bottom’ Background=’Azure’> <StatusBarItem DockPanel.Dock=’Right’> <TextBlock Text=’Welcome to WPF!!’/> </StatusBarItem> <StatusBarItem> <TextBlock Text=’Hello World! ‘/> </StatusBarItem> </StatusBar>

How do I bind a string array with a ListBox?

A ListBox can be bound with a string array using the ItemsSource property of the ListBox control. The following code snippet is used to bind a string array with the ListBox. [XAML] <Window x:Class=’WpfApplication4.Window1′ xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ Title=’Window1′ Height=’300′ Width=’300′ Loaded=’Window_Loaded’> <Grid> <ListBox Name=’LB2’/> </Grid> </Window> [C#] private void Window_Loaded(object sender, RoutedEventArgs e) { string[] lbitems = { ‘Item1’, ‘Item2’, ‘Item3’, ‘Item4’ }; LB2.ItemsSource = lbitems; }

How placing controls in a WrapPanel differs from a Grid?

Placing controls inside a WrapPanel will shrink the control to it’s minimum width or it will wrap the controls to the next line when the form’s size is reduced. But when the form’s size is increased it will not resize the control accordingly, instead, it will place the controls next to each other. On the other hand, if the controls are placed inside a Grid, it will resize the controls when the form is resized.

How do I print a form?

Unfortunately, there is no easy way to print a form. You may implement this function with the steps given below. 1. Add a print function to your application. To do this, you should add a PrintDocument component to your application. Please drag a PrintDocument from the toolbox to your form. After that, you should create a PrintDialog and add the code to print the document. [C#] private void buttonPrint_Click(object sender, EventArgs e) { PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = printDocument1; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) printDocument1.Print(); } 2. Draw the form when printing. This step is a little complex. You should handle the PrintPage of the printDocument1 and draw the form to the printer device. In the event you may copy the form to an image and then draw it to the printer device. [C#] using System.Drawing.Printing; private void printDocument1_PrintPage( object sender, PrintPageEventArgs e) { Graphics graphic = CreateGraphics(); Image memImage = new Bitmap( Size.Width, Size.Height, graphic ); Graphics memGraphic = Graphics.FromImage( memImage ); IntPtr dc1 = graphic.GetHdc(); IntPtr dc2 = memGraphic.GetHdc(); BitBlt( dc2, 0, 0, ClientRectangle.Width, ClientRectangle.Height, dc1, 0, 0, 13369376 ); graphic.ReleaseHdc( dc1 ); memGraphic.ReleaseHdc( dc2 ); e.Graphics.DrawImage( memImage, 0, 0 ); } 3. Declare the API function. Please note the BitBlt function used in Step 2. It is an unmanaged function. You should use ‘DllImport’ attribute to import it to your code. Although, this is the Step 3, you may perform this step anytime. [C#] using System.Runtime.InteropServices; [ DllImport( ‘gdi32.dll’ ) ] private static extern bool BitBlt( IntPtr hdcDest, int nXDestint nYDest, int nWidthint nHeight, IntPtr hdcSrcint nXSrcint nYSrc, System.Int32 dwRop );