Click here to Skip to main content
15,887,335 members
Home / Discussions / C#
   

C#

 
GeneralRe: prevent method execution on design time using attributes Pin
OriginalGriff8-Nov-15 4:03
mveOriginalGriff8-Nov-15 4:03 
GeneralRe: prevent method execution on design time using attributes Pin
Gilbert Consellado8-Nov-15 14:38
professionalGilbert Consellado8-Nov-15 14:38 
AnswerRe: prevent method execution on design time using attributes Pin
Nathan Minier9-Nov-15 3:18
professionalNathan Minier9-Nov-15 3:18 
Questiongdi+ shape is not a reference object in Arraylist? Pin
smallkubi7-Nov-15 5:47
smallkubi7-Nov-15 5:47 
AnswerRe: gdi+ shape is not a reference object in Arraylist? Pin
Richard MacCutchan7-Nov-15 6:14
mveRichard MacCutchan7-Nov-15 6:14 
GeneralRe: gdi+ shape is not a reference object in Arraylist? Pin
smallkubi7-Nov-15 14:01
smallkubi7-Nov-15 14:01 
GeneralRe: gdi+ shape is not a reference object in Arraylist? Pin
Richard MacCutchan7-Nov-15 21:07
mveRichard MacCutchan7-Nov-15 21:07 
AnswerRe: gdi+ shape is not a reference object in Arraylist? Pin
George Jonsson7-Nov-15 17:40
professionalGeorge Jonsson7-Nov-15 17:40 
First of all ArrayList is not recommended as the performance is not the best. See the Remarks section in ArrayList Class[^]

That said, as you cannot change the values as the Rectangle is a struct and not a class, it might be better if you implement an interface and/or an abstract base class, and then a class for each shape you want to have, Rectangle, Circle, Triangle etc. (Or whatever it is you want)
The specific shape classes all inherit the base class.
The benefit of this approach is that you can share common properties, such as Position and Size but also implement shape specific a Paint method for each class.
C#
public abstract class Base
{
    public Base()
    {
        location = new Point();
    }

    public abstract void Paint(Graphics g);

    public string ShapeName { get; protected set; }

    private Point location;
    public Point Location
    {
        get
        {
            return location;
        }
        set
        {
            location = value;
        }
    }

    private Size size;
    public Size Size
    {
        get
        {
            return size;
        }
        set
        {
            size = value;
        }
    }


    public int X
    {
        get
        {
            return location.X;
        }
        set
        {
            location.X = value;
        }
    }
}

public class Square : Base
{
    public Square(Point location, Size size)
        : base()
    {
        ShapeName = "Square";
        Location = location;
        Size = size;
    }

    public override void Paint(Graphics g)
    {
        // Implement the way to draw a square
    }
}


Then
C#
List<Base> shapes = new List<Base>();
shapes.Add(new Square(new Point(), new Size(30, 30)));
shapes[0].X = 10;

GeneralRe: gdi+ shape is not a reference object in Arraylist? Pin
smallkubi7-Nov-15 22:06
smallkubi7-Nov-15 22:06 
GeneralRe: gdi+ shape is not a reference object in Arraylist? Pin
George Jonsson7-Nov-15 22:41
professionalGeorge Jonsson7-Nov-15 22:41 
Questioncontrol of child form when using showDialog() Pin
randor6-Nov-15 13:47
randor6-Nov-15 13:47 
AnswerRe: control of child form when using showDialog() Pin
Richard Andrew x646-Nov-15 14:30
professionalRichard Andrew x646-Nov-15 14:30 
GeneralRe: control of child form when using showDialog() Pin
randor7-Nov-15 11:46
randor7-Nov-15 11:46 
GeneralRe: control of child form when using showDialog() Pin
randor7-Nov-15 11:49
randor7-Nov-15 11:49 
AnswerRe: control of child form when using showDialog() Pin
Richard Andrew x647-Nov-15 11:55
professionalRichard Andrew x647-Nov-15 11:55 
AnswerRe: control of child form when using showDialog() Pin
BillWoodruff6-Nov-15 14:43
professionalBillWoodruff6-Nov-15 14:43 
GeneralRe: control of child form when using showDialog() Pin
John Torjo7-Nov-15 3:32
professionalJohn Torjo7-Nov-15 3:32 
QuestionEmbedding custom font to PDF using iTextsharp Pin
GauravDutta5-Nov-15 22:08
GauravDutta5-Nov-15 22:08 
AnswerRe: Embedding custom font to PDF using iTextsharp Pin
Pete O'Hanlon5-Nov-15 22:39
mvePete O'Hanlon5-Nov-15 22:39 
QuestionHow to calculate Interest Rate of Loan having quarterly payment frequency and monthly compounding using c#. Pin
Member 104985445-Nov-15 19:00
Member 104985445-Nov-15 19:00 
AnswerRe: How to calculate Interest Rate of Loan having quarterly payment frequency and monthly compounding using c#. Pin
John Torjo5-Nov-15 20:08
professionalJohn Torjo5-Nov-15 20:08 
GeneralRe: How to calculate Interest Rate of Loan having quarterly payment frequency and monthly compounding using c#. Pin
Member 104985445-Nov-15 20:48
Member 104985445-Nov-15 20:48 
GeneralRe: How to calculate Interest Rate of Loan having quarterly payment frequency and monthly compounding using c#. Pin
John Torjo10-Nov-15 4:46
professionalJohn Torjo10-Nov-15 4:46 
QuestionI need help improving my code Pin
Gilbert Consellado5-Nov-15 16:38
professionalGilbert Consellado5-Nov-15 16:38 
AnswerRe: I need help improving my code Pin
John Torjo5-Nov-15 17:34
professionalJohn Torjo5-Nov-15 17:34 

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.