PC Review


Reply
Thread Tools Rate Thread

Draw ellipse with specify x,y,width, height

 
 
Slickuser
Guest
Posts: n/a
 
      29th Nov 2007
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);
}

}
}
 
Reply With Quote
 
 
 
 
Slickuser
Guest
Posts: n/a
 
      29th Nov 2007
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)
{

}

}
}
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      29th Nov 2007
On 2007-11-28 21:46:16 -0800, Slickuser <(E-Mail Removed)> said:

> 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

 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      29th Nov 2007
On Nov 29, 2:22 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
> On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gmail.com> said:
>
> > 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

 
Reply With Quote
 
MikeY
Guest
Posts: n/a
 
      29th Nov 2007
Yes Bob's pages are an excellent way of learning. Thats were I learnt how to
do my buttons
MikeY

"Chris Dunaway" <(E-Mail Removed)> wrote in message
news:3d8f45fb-8027-4941-8f6b-(E-Mail Removed)...
> On Nov 29, 2:22 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
>> On 2007-11-28 21:46:16 -0800, Slickuser <slick.us...@gmail.com> said:
>>
>> > 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I draw an ellipse on excel, or can I? M Microsoft Excel Charting 1 9th Apr 2010 09:32 PM
Draw an Ellipse on a Report Kaykayme Microsoft Access VBA Modules 4 28th Apr 2009 04:30 PM
how to Draw an ellipse using c# weird0 Microsoft C# .NET 2 16th Oct 2007 11:20 AM
how to draw crosshairs on a chart that go to the height and width of the chart and move with the cursor position? Steve Microsoft C# .NET 1 11th Sep 2006 02:41 PM
Draw Ellipse and store in gif or png file? Nanda Microsoft C# .NET 1 31st Jul 2003 04:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:11 PM.