C# tutorial-fill shapes with images


Fill shapes with images

In this page you will learn to fill the closed shapes using different images. To fill the shapes with images, You need to create a TextureBrush object from the TextureBrush class of System.Drawing library and use it to fill your shapes.

Example: filling the rectangle and ellipse with images

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsFormsApplication2

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

 

        private void Form2_Load(object sender, EventArgs e)

        {

            this.WindowState = FormWindowState.Maximized;

         

        }

  

        private void Form2_Paint(object sender, PaintEventArgs e)

        {

           

           //Create graphic object for the current form 

            Graphics gs = this.CreateGraphics();

 

            //Create a rectangle object 

            Rectangle rt = new Rectangle(20, 100, 200, 200); 

            Rectangle rt1 = new Rectangle(230, 100, 200, 200);

            //Create bitmap object to contain image in current pro. folder

            Image img = Image.FromFile("image1.bmp");

            Bitmap bimage = new Bitmap(img);

 

            //Create brush object

            TextureBrush tb = new TextureBrush(bimage);

            TextureBrush tb1 = new TextureBrush(bimage);

            //fill the shapes           

            gs.FillRectangle(tb, rt);

            gs.FillEllipse(tb1, rt1);

 

        }

       

    }

}

C# to fill shapes with images using Texture brush




Comments

Rajesh Shukla comment

 Rajesh Shukla

thanks a lot..but i need it in crystal Report in DotNet please show me an exam in case of crystal report..


2014-08-05
CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.