Click here to Skip to main content
15,395,698 members
Home / Discussions / C#
   

C#

 
GeneralRe: Drawing with c# Pin
Richard Deeming23-Jun-22 22:24
mveRichard Deeming23-Jun-22 22:24 
GeneralRe: Drawing with c# Pin
Member 1557095223-Jun-22 23:20
MemberMember 1557095223-Jun-22 23:20 
GeneralRe: Drawing with c# Pin
Victor Nijegorodov24-Jun-22 5:54
MemberVictor Nijegorodov24-Jun-22 5:54 
GeneralRe: Drawing with c# Pin
Dave Kreskowiak24-Jun-22 5:58
mveDave Kreskowiak24-Jun-22 5:58 
GeneralRe: Drawing with c# Pin
trønderen24-Jun-22 17:02
Membertrønderen24-Jun-22 17:02 
QuestionSimple Paint app in winforms Pin
Aafaan_Jii20-Jun-22 23:19
MemberAafaan_Jii20-Jun-22 23:19 
AnswerRe: Simple Paint app in winforms Pin
OriginalGriff20-Jun-22 23:40
mveOriginalGriff20-Jun-22 23:40 
AnswerRe: Simple Paint app in winforms Pin
Pete O'Hanlon21-Jun-22 2:18
mvaPete O'Hanlon21-Jun-22 2:18 
This sounds like you are planning to have some fun writing code. Before you start writing any code, make a list of your requirements so that you don't lose focus. A word of advice; when dealing with shapes, make them separate shape classes, and make it so that the responsibility of drawing the shape belongs with the shape itself. I would tend to start with an abstract shape class, like this:
C#
public abstract class BaseShape
{
  public event EventHandler ShapeInvalidated;
  private int? x;
  public int? X
  {
    get { x = value; }
    set
    {
      x = value;
      Invalidate();
    }
  }
  private int? y;
  public int? Y
  {
    get { y = value; }
    set
    {
      y = value;
      Invalidate();
    }
  }
  private int? width;
  public int? Width
  {
    get { width = value; }
    set
    {
      width = value;
      Invalidate();
    }
  }
  private int? height;
  public int? Height
  {
    get { height = value; }
    set
    {
      height = value;
      Invalidate();
    }
  }

  private int zorder;
  public int ZOrder
  {
    get { zorder = value; }
    set
    {
      zorder = value;
      Invalidate();
    }
  }


  private bool CanPaint()
  {
    return x.HasValue and y.HasValue && height.HasValue && width.HasValue && height.Value > 0 && width.Value > 0;
  }

  public void Invalidate()
  {
    if (CanPaint)
    {
      ShapeInvalidated?.Invoke(this, null);
    }
  }

  public abstract void Paint();
}

public class Rectangle : BaseShape
{
  public override void Paint()
  {
    // Draw the rectangle based on the graphic context
  }
}
In general, you would want a shape manager class to actually manage the shapes on the screen. The shape manager would receive the ShapeInvalidated event and call the Paint method on each shape using the ZOrder to control the order the items are painted so you can create overlapping shapes.

AnswerRe: Simple Paint app in winforms Pin
Dave Kreskowiak21-Jun-22 4:39
mveDave Kreskowiak21-Jun-22 4:39 
AnswerRe: Simple Paint app in winforms Pin
Gerry Schmitz21-Jun-22 4:45
mveGerry Schmitz21-Jun-22 4:45 
QuestionHTML Input Controls Value Pin
Member 1431490219-Jun-22 18:46
MemberMember 1431490219-Jun-22 18:46 
AnswerRe: HTML Input Controls Value Pin
OriginalGriff19-Jun-22 19:32
mveOriginalGriff19-Jun-22 19:32 
GeneralRe: HTML Input Controls Value Pin
Member 1431490219-Jun-22 19:47
MemberMember 1431490219-Jun-22 19:47 
GeneralRe: HTML Input Controls Value Pin
Richard Deeming19-Jun-22 21:38
mveRichard Deeming19-Jun-22 21:38 
GeneralRe: HTML Input Controls Value Pin
OriginalGriff19-Jun-22 21:51
mveOriginalGriff19-Jun-22 21:51 
GeneralRe: HTML Input Controls Value Pin
Dave Kreskowiak20-Jun-22 3:49
mveDave Kreskowiak20-Jun-22 3:49 
GeneralRe: HTML Input Controls Value Pin
Member 1431490220-Jun-22 3:56
MemberMember 1431490220-Jun-22 3:56 
GeneralRe: HTML Input Controls Value Pin
Dave Kreskowiak20-Jun-22 3:57
mveDave Kreskowiak20-Jun-22 3:57 
GeneralRe: HTML Input Controls Value Pin
Member 1431490220-Jun-22 3:58
MemberMember 1431490220-Jun-22 3:58 
GeneralRe: HTML Input Controls Value Pin
Dave Kreskowiak20-Jun-22 4:00
mveDave Kreskowiak20-Jun-22 4:00 
GeneralRe: HTML Input Controls Value Pin
Mycroft Holmes20-Jun-22 12:31
professionalMycroft Holmes20-Jun-22 12:31 
QuestionHow filter a DataGridView filled from csv file... Pin
grennday11-Jun-22 21:06
Membergrennday11-Jun-22 21:06 
AnswerRe: How filter a DataGridView filled from csv file... Pin
Richard MacCutchan11-Jun-22 21:18
mveRichard MacCutchan11-Jun-22 21:18 
GeneralRe: How filter a DataGridView filled from csv file... Pin
grennday15-Jun-22 19:40
Membergrennday15-Jun-22 19:40 
GeneralRe: How filter a DataGridView filled from csv file... Pin
Richard MacCutchan15-Jun-22 22:03
mveRichard MacCutchan15-Jun-22 22:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.