[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1215
  • Last Modified:

How do I create a circle in Visual Basic 2008 Express?

Interested in finding out how to draw a circle in VB 2008 Express
0
NerdsOfTech
Asked:
NerdsOfTech
3 Solutions
 
käµfm³d 👽Commented:
On a form?
Public Sub SomeFunction()
    System.Drawing.Graphics g = Me.CreateGraphics()
 
    g.DrawEllipse(Pens.Black, new Rectangle(0, 0, 100, 100))
 
End Sub

Open in new window

0
 
daveamourCommented:
Here you go:
        private void DrawCircle_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.DrawEllipse(new Pen(Color.Black), 100, 100, 200, 200);
        }
See attached code:
 

Form designer Code:
 
namespace CircleProject
{
    partial class MainForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.DrawCircle = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // DrawCircle
            // 
            this.DrawCircle.Location = new System.Drawing.Point(202, 30);
            this.DrawCircle.Name = "DrawCircle";
            this.DrawCircle.Size = new System.Drawing.Size(75, 23);
            this.DrawCircle.TabIndex = 0;
            this.DrawCircle.Text = "Draw Cirlce";
            this.DrawCircle.UseVisualStyleBackColor = true;
            this.DrawCircle.Click += new System.EventHandler(this.DrawCircle_Click);
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(501, 403);
            this.Controls.Add(this.DrawCircle);
            this.Name = "MainForm";
            this.Text = "Main Form";
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private System.Windows.Forms.Button DrawCircle;
    }
}
 
Form Code:
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace CircleProject
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
 
        private void DrawCircle_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
 
            g.DrawEllipse(new Pen(Color.Black), 100, 100, 200, 200);
        }
    }
}

Open in new window

0
 
daveamourCommented:
Sorry my apologies, mine was in C#  - wasn't paying attention!
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
NerdsOfTechTechnology ScientistAuthor Commented:
Yes just on a blank From1 if possible including all declarations needed.

And then 1 circle drawn would be great.
0
 
daveamourCommented:
NerdsOfTech  -see above - although mine is C# it is a complete solution
0
 
NerdsOfTechTechnology ScientistAuthor Commented:
Dave, it is a complete solution for C# not VB. If you can pull off the VB code I will award you full points.

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a dashed circle...
(though it should be easy enough to see the relevant code in C# and simply remove the semi-color ";" off the end of the line)
Imports System.Drawing.Drawing2D
Public Class Form1
 
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim myPen As Pen = New Pen(Color.Black, 4)
        myPen.DashStyle = DashStyle.DashDotDot
        e.Graphics.DrawEllipse(myPen, 25, 25, 500, 500)
        myPen.Dispose()
    End Sub
 
End Class

Open in new window

DashedEllipse.jpg
0
 
daveamourCommented:
Other people have posted solutions in VB.net - they haven't given you eevery single line of code but sureley you can follow what they have shown you?  It really is very straightforward.
0
 
NerdsOfTechTechnology ScientistAuthor Commented:
Thank you all!
0
 
NerdsOfTechTechnology ScientistAuthor Commented:
EExcellent work everyone! Thank you for your help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now