473,791 Members | 3,275 Online
Bytes | Software Development & Data Engineering Community
+ 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.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

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

InitializeCompo nent();
}

private void Form1_Load(obje ct 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.CreateGrap hics();
g.FillEllipse(B rushes.Blue, x1, y1, w, h);
}

}
}
Nov 29 '07 #1
4 3975
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.Collecti ons.Generic;
using System.Componen tModel;
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()
{

InitializeCompo nent();
draw(50, 80, 50, 150);

}

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

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

}

private void draw(int x1, int y1, int w, int h)
{
Graphics dc = this.CreateGrap hics();
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*********@gm ail.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...@Nn OwSlPiAnMk.comw rote:
On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gm ail.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******** *************** ***********@x69 g2000hsx.google groups.com...
On Nov 29, 2:22 am, Peter Duniho <NpOeStPe...@Nn OwSlPiAnMk.comw rote:
>On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gm ail.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
1946
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. Fill out this form to register and you may be eligible for our monthly draw.
1
4751
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(); bmp.Save(filename,System.Drawing.Imaging.ImageFormat.Gif); HTH,
3
4266
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 of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
4
30826
by: Jason Huang | last post by:
Hi, In my C# Windows Form, how do I draw a Line? Thanks for help. Jason
7
10693
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 original one? (the current attempts all draw the border just outside of the original rectangle). At the moment im using the following code, but it allows the rectangle to grow - which i definately dont want!
5
9243
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 Ellipse Drawing Function. The following code I found on Google works in VB5 and draws an ellipse shape no problem using the Circle Method. Private Sub cmdDrawEllipse_Click() Dim X As Long, Y As Long Dim ElipseWidth As Integer, ElipseHeight As...
0
435
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 RenderTargetBitmap rtb = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
0
1248
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> <EllipseGeometry Center="0,0" RadiusX="1" RadiusY="1"> <EllipseGeometry.Transform> <MatrixTransform> <MatrixTransform.Matrix> <Matrix M11="76.5" M12="0" M21="0" M22="-27"
1
5135
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 following code. in the following code i am using SelectionArea class which extends a canvas on which i am performing drawing operation. i am using image variable in this class for double buffering to reduce flickering and to save the applet's previous...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3718
muto222
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.