C# Tutorial – Make a Meme Maker App in Windows Form Application and Visual Studio

In this tutorial we will demonstrate how to make a fun meme maker app using windows form application and C# programming. We will use of the built in functions and use the already available components from visual studio to make this app. This app uses picture box, labels, text boxes and buttons only. You can import a picture to the app, add the top text and the bottom text for the meme, select a color of the text and click save to save the file as a JPG image in the hard drive. This will be a really app to make in windows form because its something we can use and also build upon to match the new meme templates.

Lesson objectives –

  1. Create a meme maker app in windows form and visual studio
  2. Load external image to the app and load it on the picture box
  3. Use text boxes to change label texts on the image
  4. Use different buttons to change text color on the app
  5. Save the image as JPG file using the Drawing.Imaging namespace
  6. have fun making tons of memes

 

Video Tutorial

 

Download The Classic Meme Templates Here

Download The meme Maker Project on GitHub

Full Source Code –

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Drawing.Imaging; // this one is for saving JPG images

namespace Meme_Maker_with_MOO_ICT
{
    public partial class Form1 : Form
    {

        OpenFileDialog openImageFile;


        public Form1()
        {
            InitializeComponent();

            SetUpApp();
        }

        private void SetUpApp()
        {
            imgPreview.Controls.Add(lblTopText);
            imgPreview.Controls.Add(lblBottomText);

            lblTopText.Location = new Point(0, 0);

            lblBottomText.Location = new Point(0, 350);

            imgPreview.SendToBack();

        }

        private void ChangeTopText(object sender, EventArgs e)
        {
            lblTopText.Text = txtTopTextBox.Text;
        }

        private void ChangeBottomText(object sender, EventArgs e)
        {
            lblBottomText.Text = txtBottomTextBox.Text;
        }

        private void OpenImage(object sender, EventArgs e)
        {

            openImageFile = new OpenFileDialog();

            openImageFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            openImageFile.Filter = "Image Files Only (*.jpg, *.gif, *.png, *.bmp) | *.jpg; *.gif; *.png; *.bmp";


            if (openImageFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    imgPreview.Image = Image.FromFile(openImageFile.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error!, Couldn't load the file" + ex.Message);
                }
            }


        }

        private void SaveImage(object sender, EventArgs e)
        {

            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.FileName = "Meme with MOO ICT";
            saveDialog.DefaultExt = "jpg";
            saveDialog.Filter = "JPG Image | *.jpg";
            saveDialog.ValidateNames = true;

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                int width = Convert.ToInt32(imgPreview.Width);
                int height = Convert.ToInt32(imgPreview.Height);
                Bitmap bmp = new Bitmap(width, height);
                imgPreview.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));
                bmp.Save(saveDialog.FileName, ImageFormat.Jpeg);
            }
        }

        private void ChangeTextColour(object sender, EventArgs e)
        {
            Button tempButton = sender as Button;

            lblTopText.ForeColor = tempButton.BackColor;
            lblBottomText.ForeColor = tempButton.BackColor;
        }
    }
}

 




Comments are closed.