locked
How to set an image as a background for button.. in C# coding.. RRS feed

  • Question

  •  

    How to set an image as a background for button..

    i have used the following code in XAML but i need it in C# Coding..

     

    <Button HorizontalAlignment="Center" Name="btntoolstrip" VerticalAlignment="Top" Width="34.5" Height="83" MouseEnter="Button_MouseEnter" Margin="0,10,0,0">

    <Button.Background >

    <ImageBrush ImageSource ="pack://siteoforigin:,,,/images/next.jpg" Stretch="Uniform"></ImageBrush>

    </Button.Background>

    </Button>

    Friday, July 6, 2007 1:16 PM

Answers

  • try something like this

     

    ImageBrush brush = new ImageBrush(new BitmapImage(new Uri("pack://siteoforigin:,,,/images/yourimage.gif")));

    brush.Stretch = Stretch.Uniform;

    btn.Background = brush;

     

    Friday, July 6, 2007 2:59 PM

All replies

  • I think that this is right:
      btntoolstrip.Image =System.Drawing.Image.FromFile(@"pack://siteoforigin:,,,/images/next.jpg");

    Friday, July 6, 2007 2:44 PM
  •  

    I cannot get the Image property for btntoolstrip

     

    Error 35 'System.Windows.Controls.Button' does not contain a definition for 'Image' 

    Friday, July 6, 2007 2:52 PM
  • try something like this

     

    ImageBrush brush = new ImageBrush(new BitmapImage(new Uri("pack://siteoforigin:,,,/images/yourimage.gif")));

    brush.Stretch = Stretch.Uniform;

    btn.Background = brush;

     

    Friday, July 6, 2007 2:59 PM
  • Try this:

    using System.Drawing;
    using System.Drawing.Imaging;
    Friday, July 6, 2007 3:02 PM
  •  

     

     Yes friends.. now its working..

     

    Thanks a Lot ..

    Friday, July 6, 2007 3:17 PM