473,473 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Draw ellipse with specify x,y,width, height

I am trying to draw an ellipse with specify x,y,width, and height for
input argument in C# .net (Visual Studio 2005).

It seem it will not draw for me. What am I missing?

See the code below, thanks.
//CODE

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

namespace test
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
draw(10, 20, 20, 50);
draw(50, 80, 50, 150);
}

private void draw(int x1, int y1, int w, int h)
{
Graphics g = this.CreateGraphics();
g.FillEllipse(Brushes.Blue, x1, y1, w, h);
}

}
}
Nov 29 '07 #1
4 3961
I got it to work but when I added in the GroupBox.

It show in the back and group is over it. Is there a way set it to
back or show the drawing the group box as well?

Here is the update code:

///code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Media;

namespace test
{
public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
draw(50, 80, 50, 150);

}

private void Form1_Load(object sender, EventArgs e)
{
draw(10, 20, 20, 50);

//SoundPlayer simpleSound = new SoundPlayer(@"C:
\911.wav");
// simpleSound.Play();

}

private void draw(int x1, int y1, int w, int h)
{
Graphics dc = this.CreateGraphics();
this.Show();

dc.FillEllipse(Brushes.Blue, x1, y1, w, h);

Pen RedPen = new Pen(Color.Red, 2);
dc.DrawEllipse(RedPen, x1, y1, w, h);
}

private void groupBox1_Enter(object sender, EventArgs e)
{

}

}
}
Nov 29 '07 #2
On 2007-11-28 21:46:16 -0800, Slickuser <sl*********@gmail.comsaid:
I got it to work but when I added in the GroupBox.

It show in the back and group is over it. Is there a way set it to
back or show the drawing the group box as well?
You are doing it wrong. You cannot just draw whenever you want. You
need to override the OnPaint() method, or subscribe to the Paint event,
and only draw there.

Search on those names ("OnPaint" and "Paint") in this newsgroup for a
number of related threads, including one that is as recent as today and
includes very specific details regarding the correct way to draw in a
form.

Pete

Nov 29 '07 #3
On Nov 29, 2:22 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gmail.comsaid:
I got it to work but when I added in the GroupBox.
It show in the back and group is over it. Is there a way set it to
back or show the drawing the group box as well?

You are doing it wrong. You cannot just draw whenever you want. You
need to override the OnPaint() method, or subscribe to the Paint event,
and only draw there.

Search on those names ("OnPaint" and "Paint") in this newsgroup for a
number of related threads, including one that is as recent as today and
includes very specific details regarding the correct way to draw in a
form.

Pete
Or you can try this link and look at the number 1 FAQ:

http://www.bobpowell.net/faqmain.htm

Chris

Nov 29 '07 #4
Yes Bob's pages are an excellent way of learning. Thats were I learnt how to
do my buttons
MikeY

"Chris Dunaway" <du******@gmail.comwrote in message
news:3d**********************************@x69g2000 hsx.googlegroups.com...
On Nov 29, 2:22 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
>On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gmail.comsaid:
I got it to work but when I added in the GroupBox.
It show in the back and group is over it. Is there a way set it to
back or show the drawing the group box as well?

You are doing it wrong. You cannot just draw whenever you want. You
need to override the OnPaint() method, or subscribe to the Paint event,
and only draw there.

Search on those names ("OnPaint" and "Paint") in this newsgroup for a
number of related threads, including one that is as recent as today and
includes very specific details regarding the correct way to draw in a
form.

Pete

Or you can try this link and look at the number 1 FAQ:

http://www.bobpowell.net/faqmain.htm

Chris

Nov 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Florida Draw | last post by:
------=_NextPart_000_0012_1D5428A2.65C196F8 Content-Type: text/plain Content-Transfer-Encoding: 8bit Sign-up for the FREE Holiday Giveaway Draw You must register to be eligible for the draw....
1
by: Nanda | last post by:
hi, try this, bmp=new Bitmap(Width,Height); g=Graphics.FromImage(bmp); g.DrawEllipse(Pens.Red, new Rectangle(0, 0, 100, 100)); g.Save();...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
4
by: Jason Huang | last post by:
Hi, In my C# Windows Form, how do I draw a Line? Thanks for help. Jason
7
by: Mark Ingram | last post by:
Hi, how can i draw a rounded rectange, with a border within a specified area? i.e. if i have a Rectangle with width and height of 100, how can i draw a rectange with 2 pixel border inside of the...
5
by: lgeastwood | last post by:
I have tweaked the PictureBox97.mdb (Stephen Lebans <www.lebans.com>) code to nicely draw lines, rectangles and circles to the specs that I input. I'm at a loss though with trying to setup an...
0
by: Tem | last post by:
I need to draw a black circle using WPF and generate an image file. I used the following but it resulted in a blank file. I cannot figure out what is wrong with it. Thanks, Tem ...
0
by: gao1183 | last post by:
I am given an Ellipse in the following definition: <Path Name="_Display2_Ellipse2" Height="50" Width="60" Stroke="black" StrokeThickness="1" Fill="teal" Visibility="Visible"> <Path.Data>...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.