Drawing shapes in a GDI window












0












$begingroup$


I've been tasked with writing a windows form application that offers some options to modify the drawing of shapes within another window. I have very little experience with event-driven programming and I'd like to improve my skill.



using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GDIDrawer;

namespace ICA3
{
public enum ShapeType
{
Square,
Circle
};

public partial class master : Form
{
const int _HEIGHT = 600;
const int _WIDTH = 800;
const int _SIZE = 50;

Color DEFAULT_COLOR = Color.Red;
Color CURRENT_COLOR;
CDrawer dr = new CDrawer(_WIDTH, _HEIGHT);
shapeform sf = new shapeform();

public master()
{
InitializeComponent();
}

private void master_btn_start_Click(object sender, EventArgs e)
{
CURRENT_COLOR = DEFAULT_COLOR;
master_timer.Start();
}

private void master_btn_stop_Click(object sender, EventArgs e)
{
master_timer.Stop();
}

private void master_btn_color_Click(object sender, EventArgs e)
{
using (ColorDialog cd = new ColorDialog())
{
if (cd.ShowDialog() == DialogResult.OK)
{
CURRENT_COLOR = cd.Color;
}
}
}

private void master_btn_shape_Click(object sender, EventArgs e)
{
sf.ShowDialog();
}

private void master_timer_Tick(object sender, EventArgs e)
{
Point pt = new Point();

//borders
if (sf._BORDER)
{
if (sf.shape == ShapeType.Circle)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
}
}

else if (sf.shape == ShapeType.Square)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
}
}
}

//no borders
else
{
if (sf.shape == ShapeType.Circle)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR);
}
}

else if (sf.shape == ShapeType.Square)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR);
}
}
}
}
}
}


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

namespace ICA3
{
public partial class shapeform : Form
{
ShapeType _SHAPE;
public bool _BORDER = false;

public ShapeType shape
{
get { return _SHAPE; }

}

public bool BorderChecked
{
get { return shapeform_cb_border.Checked; }
}

public shapeform()
{
InitializeComponent();
}

private void shapeform_btn_ok_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}

private void shapeform_btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
}

private void shapeform_cb_border_CheckedChanged(object sender, EventArgs e)
{
_BORDER = shapeform_cb_border.Checked;
}

private void shapeform_rb_circle_CheckedChanged(object sender, EventArgs e)
{
_SHAPE = ShapeType.Circle;
}

private void shapeform_rb_square_CheckedChanged(object sender, EventArgs e)
{
_SHAPE = ShapeType.Square;
}

}
}


I'm trying to learn the best practices in C# and Windows forms, so tips are much appreciated.










share|improve this question







New contributor




Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    0












    $begingroup$


    I've been tasked with writing a windows form application that offers some options to modify the drawing of shapes within another window. I have very little experience with event-driven programming and I'd like to improve my skill.



    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using GDIDrawer;

    namespace ICA3
    {
    public enum ShapeType
    {
    Square,
    Circle
    };

    public partial class master : Form
    {
    const int _HEIGHT = 600;
    const int _WIDTH = 800;
    const int _SIZE = 50;

    Color DEFAULT_COLOR = Color.Red;
    Color CURRENT_COLOR;
    CDrawer dr = new CDrawer(_WIDTH, _HEIGHT);
    shapeform sf = new shapeform();

    public master()
    {
    InitializeComponent();
    }

    private void master_btn_start_Click(object sender, EventArgs e)
    {
    CURRENT_COLOR = DEFAULT_COLOR;
    master_timer.Start();
    }

    private void master_btn_stop_Click(object sender, EventArgs e)
    {
    master_timer.Stop();
    }

    private void master_btn_color_Click(object sender, EventArgs e)
    {
    using (ColorDialog cd = new ColorDialog())
    {
    if (cd.ShowDialog() == DialogResult.OK)
    {
    CURRENT_COLOR = cd.Color;
    }
    }
    }

    private void master_btn_shape_Click(object sender, EventArgs e)
    {
    sf.ShowDialog();
    }

    private void master_timer_Tick(object sender, EventArgs e)
    {
    Point pt = new Point();

    //borders
    if (sf._BORDER)
    {
    if (sf.shape == ShapeType.Circle)
    {
    if (dr.GetLastMouseLeftClick(out pt))
    {
    dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
    }
    }

    else if (sf.shape == ShapeType.Square)
    {
    if (dr.GetLastMouseLeftClick(out pt))
    {
    dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
    }
    }
    }

    //no borders
    else
    {
    if (sf.shape == ShapeType.Circle)
    {
    if (dr.GetLastMouseLeftClick(out pt))
    {
    dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR);
    }
    }

    else if (sf.shape == ShapeType.Square)
    {
    if (dr.GetLastMouseLeftClick(out pt))
    {
    dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR);
    }
    }
    }
    }
    }
    }


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

    namespace ICA3
    {
    public partial class shapeform : Form
    {
    ShapeType _SHAPE;
    public bool _BORDER = false;

    public ShapeType shape
    {
    get { return _SHAPE; }

    }

    public bool BorderChecked
    {
    get { return shapeform_cb_border.Checked; }
    }

    public shapeform()
    {
    InitializeComponent();
    }

    private void shapeform_btn_ok_Click(object sender, EventArgs e)
    {
    this.DialogResult = DialogResult.OK;
    }

    private void shapeform_btn_cancel_Click(object sender, EventArgs e)
    {
    this.Close();
    }

    private void shapeform_cb_border_CheckedChanged(object sender, EventArgs e)
    {
    _BORDER = shapeform_cb_border.Checked;
    }

    private void shapeform_rb_circle_CheckedChanged(object sender, EventArgs e)
    {
    _SHAPE = ShapeType.Circle;
    }

    private void shapeform_rb_square_CheckedChanged(object sender, EventArgs e)
    {
    _SHAPE = ShapeType.Square;
    }

    }
    }


    I'm trying to learn the best practices in C# and Windows forms, so tips are much appreciated.










    share|improve this question







    New contributor




    Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      I've been tasked with writing a windows form application that offers some options to modify the drawing of shapes within another window. I have very little experience with event-driven programming and I'd like to improve my skill.



      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using GDIDrawer;

      namespace ICA3
      {
      public enum ShapeType
      {
      Square,
      Circle
      };

      public partial class master : Form
      {
      const int _HEIGHT = 600;
      const int _WIDTH = 800;
      const int _SIZE = 50;

      Color DEFAULT_COLOR = Color.Red;
      Color CURRENT_COLOR;
      CDrawer dr = new CDrawer(_WIDTH, _HEIGHT);
      shapeform sf = new shapeform();

      public master()
      {
      InitializeComponent();
      }

      private void master_btn_start_Click(object sender, EventArgs e)
      {
      CURRENT_COLOR = DEFAULT_COLOR;
      master_timer.Start();
      }

      private void master_btn_stop_Click(object sender, EventArgs e)
      {
      master_timer.Stop();
      }

      private void master_btn_color_Click(object sender, EventArgs e)
      {
      using (ColorDialog cd = new ColorDialog())
      {
      if (cd.ShowDialog() == DialogResult.OK)
      {
      CURRENT_COLOR = cd.Color;
      }
      }
      }

      private void master_btn_shape_Click(object sender, EventArgs e)
      {
      sf.ShowDialog();
      }

      private void master_timer_Tick(object sender, EventArgs e)
      {
      Point pt = new Point();

      //borders
      if (sf._BORDER)
      {
      if (sf.shape == ShapeType.Circle)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
      }
      }

      else if (sf.shape == ShapeType.Square)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
      }
      }
      }

      //no borders
      else
      {
      if (sf.shape == ShapeType.Circle)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR);
      }
      }

      else if (sf.shape == ShapeType.Square)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR);
      }
      }
      }
      }
      }
      }


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

      namespace ICA3
      {
      public partial class shapeform : Form
      {
      ShapeType _SHAPE;
      public bool _BORDER = false;

      public ShapeType shape
      {
      get { return _SHAPE; }

      }

      public bool BorderChecked
      {
      get { return shapeform_cb_border.Checked; }
      }

      public shapeform()
      {
      InitializeComponent();
      }

      private void shapeform_btn_ok_Click(object sender, EventArgs e)
      {
      this.DialogResult = DialogResult.OK;
      }

      private void shapeform_btn_cancel_Click(object sender, EventArgs e)
      {
      this.Close();
      }

      private void shapeform_cb_border_CheckedChanged(object sender, EventArgs e)
      {
      _BORDER = shapeform_cb_border.Checked;
      }

      private void shapeform_rb_circle_CheckedChanged(object sender, EventArgs e)
      {
      _SHAPE = ShapeType.Circle;
      }

      private void shapeform_rb_square_CheckedChanged(object sender, EventArgs e)
      {
      _SHAPE = ShapeType.Square;
      }

      }
      }


      I'm trying to learn the best practices in C# and Windows forms, so tips are much appreciated.










      share|improve this question







      New contributor




      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I've been tasked with writing a windows form application that offers some options to modify the drawing of shapes within another window. I have very little experience with event-driven programming and I'd like to improve my skill.



      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using GDIDrawer;

      namespace ICA3
      {
      public enum ShapeType
      {
      Square,
      Circle
      };

      public partial class master : Form
      {
      const int _HEIGHT = 600;
      const int _WIDTH = 800;
      const int _SIZE = 50;

      Color DEFAULT_COLOR = Color.Red;
      Color CURRENT_COLOR;
      CDrawer dr = new CDrawer(_WIDTH, _HEIGHT);
      shapeform sf = new shapeform();

      public master()
      {
      InitializeComponent();
      }

      private void master_btn_start_Click(object sender, EventArgs e)
      {
      CURRENT_COLOR = DEFAULT_COLOR;
      master_timer.Start();
      }

      private void master_btn_stop_Click(object sender, EventArgs e)
      {
      master_timer.Stop();
      }

      private void master_btn_color_Click(object sender, EventArgs e)
      {
      using (ColorDialog cd = new ColorDialog())
      {
      if (cd.ShowDialog() == DialogResult.OK)
      {
      CURRENT_COLOR = cd.Color;
      }
      }
      }

      private void master_btn_shape_Click(object sender, EventArgs e)
      {
      sf.ShowDialog();
      }

      private void master_timer_Tick(object sender, EventArgs e)
      {
      Point pt = new Point();

      //borders
      if (sf._BORDER)
      {
      if (sf.shape == ShapeType.Circle)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
      }
      }

      else if (sf.shape == ShapeType.Square)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
      }
      }
      }

      //no borders
      else
      {
      if (sf.shape == ShapeType.Circle)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR);
      }
      }

      else if (sf.shape == ShapeType.Square)
      {
      if (dr.GetLastMouseLeftClick(out pt))
      {
      dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR);
      }
      }
      }
      }
      }
      }


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

      namespace ICA3
      {
      public partial class shapeform : Form
      {
      ShapeType _SHAPE;
      public bool _BORDER = false;

      public ShapeType shape
      {
      get { return _SHAPE; }

      }

      public bool BorderChecked
      {
      get { return shapeform_cb_border.Checked; }
      }

      public shapeform()
      {
      InitializeComponent();
      }

      private void shapeform_btn_ok_Click(object sender, EventArgs e)
      {
      this.DialogResult = DialogResult.OK;
      }

      private void shapeform_btn_cancel_Click(object sender, EventArgs e)
      {
      this.Close();
      }

      private void shapeform_cb_border_CheckedChanged(object sender, EventArgs e)
      {
      _BORDER = shapeform_cb_border.Checked;
      }

      private void shapeform_rb_circle_CheckedChanged(object sender, EventArgs e)
      {
      _SHAPE = ShapeType.Circle;
      }

      private void shapeform_rb_square_CheckedChanged(object sender, EventArgs e)
      {
      _SHAPE = ShapeType.Square;
      }

      }
      }


      I'm trying to learn the best practices in C# and Windows forms, so tips are much appreciated.







      c# event-handling winforms






      share|improve this question







      New contributor




      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 14 mins ago









      DumbassahedratronDumbassahedratron

      11




      11




      New contributor




      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Dumbassahedratron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Dumbassahedratron is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212508%2fdrawing-shapes-in-a-gdi-window%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Dumbassahedratron is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Dumbassahedratron is a new contributor. Be nice, and check out our Code of Conduct.













          Dumbassahedratron is a new contributor. Be nice, and check out our Code of Conduct.












          Dumbassahedratron is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212508%2fdrawing-shapes-in-a-gdi-window%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар