Draw ellipse with specify x,y,width, height

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Slickuser

    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);
    }

    }
    }
  • Slickuser

    #2
    Re: Draw ellipse with specify x,y,width, height

    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)
    {

    }

    }
    }

    Comment

    • Peter Duniho

      #3
      Re: Draw ellipse with specify x,y,width, height

      On 2007-11-28 21:46:16 -0800, Slickuser <slick.users@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

      Comment

      • Chris Dunaway

        #4
        Re: Draw ellipse with specify x,y,width, height

        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:



        Chris

        Comment

        • MikeY

          #5
          Re: Draw ellipse with specify x,y,width, height

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

          "Chris Dunaway" <dunawayc@gmail .comwrote in message
          news:3d8f45fb-8027-4941-8f6b-3c8a0818c1cc@x6 9g2000hsx.googl egroups.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:
          >

          >
          Chris
          >

          Comment

          Working...