Register Now

Login


Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Smiley Face in Vb.Net

To create a Smiley Face in VB.Net, you can use the Graphics class and the DrawEllipse and DrawArc methods to draw the face and the eyes, and the FillEllipse method to fill in the pupils.


Here are the steps to create a Smiley Face in VB.Net:

  1. Create a new Windows Forms project in Visual Studio.
  2. Drag and drop a PictureBox control from the toolbox to the form.
  3. Double-click on the form to generate the default Form1_Load event.
  4. In the Form1_Load event, create an instance of the Graphics class and assign it to the PictureBox’s Graphics property.
  5. Use the DrawEllipse method of the Graphics class to draw the face of the smiley, passing in the appropriate pen and rectangle arguments.
  6. Use the DrawEllipse method again to draw the eyes of the smiley, passing in the appropriate pen and rectangle arguments.
  7. Use the FillEllipse method of the Graphics class to fill in the pupils of the eyes, passing in the appropriate brush and rectangle arguments.
  8. Use the DrawArc method of the Graphics class to draw the mouth of the smiley, passing in the appropriate pen, rectangle and start and sweep angles.
  9. Optional: Add any additional functionality or interaction you want to the smiley face, like changing color when clicking on it.
  10. Run the project to see the smiley face on the form.

Keep in mind that this is a simple example and you can use other controls, like buttons, to change the color or add more interactions. Also you can change the size and position of the smiley face as you wish by modifying the arguments passed to the DrawEllipse, FillEllipse and DrawArc methods.


Here is an example of how you could create a Smiley Face in VB.Net:

Dim g As Graphics
g = Me.CreateGraphics()

' Draw the face
g.DrawEllipse(Pens.Yellow, 50, 50, 200, 200)

' Draw the eyes
g.DrawEllipse(Pens.Black, 100, 100, 20, 20)
g.DrawEllipse(Pens.Black, 180, 100, 20, 20)

' Fill in the pupils
g.FillEllipse(Brushes.Black, 110, 110, 10, 10)
g.FillEllipse(Brushes.Black, 190, 110, 10, 10)

' Draw the mouth
g.DrawArc(Pens.Black, 100, 150, 100, 50, 0, -180)

This code creates a yellow ellipse for the face, black ellipses for the eyes, and black circles for the pupils. It also creates an arc for the smile. The Graphics class is the base class for all drawing in GDI+. The DrawEllipse method is used to draw an ellipse, the FillEllipse method is used to fill the pupils, and the DrawArc method is used to draw an arc. The numbers passed as arguments to these methods determine the position and size of the shapes on the form.

Note that this is an example of how to draw a smiley face in a windows form, you can also use other controls like a picture box to display the smiley face and add more interactions and functionalities.


Leave a reply