Simple guide on how to use picture box custom properties - Bunifu Framework | Empowering software developers craft great user experiences in less time. Productivity tools for C# & VB.NET UX/UI design

Simple guide on how to use picture box custom properties

Achieve beautiful dashboard panels in your project using shadow panel
June 29, 2018
Bunifu Framework For Education
Introducing education plan for students, teachers and academics
July 3, 2018
Show all

Simple guide on how to use picture box custom properties

BunifuPictureBox is a customizable Picturebox in that you can achieve your desired look with a few property changes and also you can give your project a modern look with round edged images.

BunifuPicturebox has many properties but we are going to look at these custom properties;

BorderRadius -Gets or Sets the border radius of the picturebox
IsCircle – Gets or Sets the IsCircle property of the picturebox for exact amount of radius to height ratio
Type – Sets the Type of shape the control takes.

To achieve a quick circular picturebox, toggle the IsCircle property and you will be good to go and if you wish to have a picturebox with custom edges change the values of BorderRadius to your desired amount.

Setting Image for BunifuPictureBox

Apart from the normal way of setting an image from a resource as shown above – here are a few ways to set BunifuPictureBox Image.

  • From Url
  • From Database

From Url

This can be achieved by using two methods

  • WebClient
//initialize your webclient
 System.Net.WebClient webClient = new System.Net.WebClient();

//Download and save your file on form load or button click - whichever you like
  webClient.DownloadFileAsync(new Uri(""), "image.jpg");
//create an event
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
// set the image when the file download is completed
 private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  //set your image
  bunifuPictureBox1.Image = Image.FromFile("image.jpg"); 

You can also set an Image directly by loading



From database

You can achieve this by using this code assuming you have your images saved in pictures table and a field called image and getting them using id value

 private Image GetImage(string id)
            using (var conn = new MySqlConnection(ConnectionString))
            using (var cmd = conn.CreateCommand())
                cmd.CommandText = "SELECT image FROM pictures WHERE id = ?id";
                cmd.Parameters.AddWithValue("?id", id);
                using (var reader = cmd.ExecuteReader())
                    if (!reader.Read())
                        return null;

                    const int CHUNK_SIZE = 2 * 1024;
                    byte[] buffer = new byte[CHUNK_SIZE];
                    long bytesRead;
                    long fieldOffset = 0;
                    using (var stream = new MemoryStream())
                        while ((bytesRead = reader.GetBytes(reader.GetOrdinal("image"), fieldOffset, buffer, 0, buffer.Length)) == buffer.Length)
                            stream.Write(buffer, 0, (int)bytesRead);
                            fieldOffset += bytesRead;
                        return Image.FromStream(stream);



and then just set your image

//provide your id
bunifuPictureBox1.Image = = GetImage("1");


Thanks for your time

Please find the attached source code for reference and more of how to save image and the sort.



Amos Chepchieng
Amos Chepchieng
Software Developer, Bunifu Framework

Leave a Reply

Your email address will not be published. Required fields are marked *

Ends in
00 Days
00 Hrs
00 Mins
00 Secs
Get 30% off any purchase in September! Use discount code BNFSEPT30SALE
Buy Now