Click here to Skip to main content
15,890,527 members
Home / Discussions / C#
   

C#

 
AnswerRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
Wes Aday19-Apr-14 10:34
professionalWes Aday19-Apr-14 10:34 
GeneralRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
rattlerrFx19-Apr-14 12:10
rattlerrFx19-Apr-14 12:10 
GeneralRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
Wes Aday20-Apr-14 2:22
professionalWes Aday20-Apr-14 2:22 
GeneralRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
rattlerrFx20-Apr-14 4:24
rattlerrFx20-Apr-14 4:24 
GeneralRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
Wes Aday20-Apr-14 4:29
professionalWes Aday20-Apr-14 4:29 
SuggestionRe: DoubleClick Selected Row Datagrid (C# WPF Project) Pin
Richard MacCutchan19-Apr-14 21:20
mveRichard MacCutchan19-Apr-14 21:20 
QuestionDisplaying UTM coordinates on a form Pin
Member 1068390219-Apr-14 8:07
Member 1068390219-Apr-14 8:07 
QuestionDraw a Line within a class and inheritance Pin
Member 1075956718-Apr-14 16:55
Member 1075956718-Apr-14 16:55 
I'm currently stuck in a exercise I'm doing and I fear I may be over thinking this, I'm trying to set up the code for a Line class and have two other Line classes each with their own thickness but can't think of anyother way besides g.DrawLine(Pens.Black, 50, 40, 126, 211); and because from how I have my code set up from class with having the DefaultLineThickness it won't cut it.


I've researched but found nothing but simple examples such as the one given and played around different methods. If anyone could help me out it'd be much appreciative. This is my current stand point.
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bicycle
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;


            
            
           // Making a random thick black line
           LineOne l1 = new LineOne(new PointF(50, 40, 126, 211);
           l1.setFilledState(false);
           l1.setLineColor(Color.Black);
           l1.Draw(g);
           

            sRectangle r2 = new sRectangle(new PointF(151, 160));
            r2.setFilledState(true);
            r2.setLineColor(Color.Green);
            r2.setFilledColor(Color.Honeydew);
            r2.Draw(g);

            sRectangleEmpty r1 = new sRectangleEmpty(new PointF(150, 150));
            r1.setFilledState(false);
            r1.setLineColor(Color.Blue);
            r1.Draw(g);
            
            sCircle c1 = new sCircle(new PointF(180, 130));
            c1.setFilledState(true);
            c1.setLineColor(Color.Orange);
            c1.setFilledColor(Color.Ivory);
            c1.Draw(g);

            sCircleEmpty c2 = new sCircleEmpty(new PointF(120, 130));
            c2.setFilledState(false);
            c2.setLineColor(Color.Black);
            c2.Draw(g);


           

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        
    }
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Bicycle
{
    class Shape
    {
        private Color DefaultLineColor = Color.Black;
        private Color DefaultFillColor = Color.Blue;
        private float DefaultLineThickness = 2;
        protected bool bOutLine;
        protected bool bFilled;
        protected Pen pen;
        protected Brush brush;
        protected PointF location;

        private void setDrawingAttributes()
        {
            pen = new Pen(DefaultLineColor, DefaultLineThickness);
            brush = new SolidBrush(DefaultFillColor);
        }

        private void init()
        {
            bOutLine = true;
            setDrawingAttributes();
        }

        public Shape()
        {
            init();
        }

        public Shape(PointF p)
        {
            location = p;
            init();
        }

        public Color getFillColor()
        {
            return (DefaultFillColor);
        }

        public bool getFilledState()
        {
            return (bFilled);
        }

        public Color getLineColor()
        {
            return (DefaultLineColor);
        }

        public float getLineThickness()
        {
            return (DefaultLineThickness);
        }

        public bool getOutLineState()
        {
            return (bOutLine);
        }

        public bool isOutLine()
        {
            return (bOutLine);
        }

        public bool isFilled()
        {
            return (bFilled);
        }

        public void setFilledColor(Color C)
        {
            DefaultFillColor = C;
            setDrawingAttributes();
        }

        public void setLineColor(Color C)
        {
            DefaultLineColor = C;
            setDrawingAttributes();
        }

        public void setLineThickness(float value)
        {
            DefaultLineThickness = value;
            setDrawingAttributes();
        }


        public void setFilledState(bool value)
        {
            bFilled = value;
        }

        public void setOutLineState(bool value)
        {
            bOutLine = value;
        }

        

    }


    
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Bicycle
{
    class sRectangle 
        : Shape
        
    {
            private bool bCenterPivot = true;
            private float width = 20;
            private float height = 20;
            protected RectangleF rect;
            private SizeF size;

            private void initRectangle()
            {
                SizeF offset = new SizeF(size.Width / 2, size.Height / 2);
                PointF p1 = PointF.Subtract(location, offset);
                rect = new RectangleF(p1, size);
            }

            private void init()
            {
                bCenterPivot = true;
                initRectangle();
                setLineColor(Color.DarkBlue);
            }

            public sRectangle()
            {
                size = new SizeF(width, height);
                init();
            }

            public sRectangle(PointF p)
                : base(p)
            {
                size = new SizeF(width, height);
                init();
            }

            public SizeF getSize()
            {
                return (size);
            }

            public void setSize(float value)
            {
                size = new SizeF(value, value);
                initRectangle();
            }

            public void setSize(float W, float H)
            {
                width = W;
                height = H;
                size = new SizeF(width, height);
                initRectangle();
            }

            public virtual void Draw(Graphics g)
            {
                if (bFilled)
                    g.FillRectangle(brush, rect);

                if (bOutLine)
                    g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
            }


           
        
    }
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Bicycle
{
    class sRectangleEmpty
        : Shape
    {
        private bool bCenterPivot = true;
        private float width = 100;
        private float height = 100;
        protected RectangleF rect;
        private SizeF size;

        private void initRectangle()
        {
            SizeF offset = new SizeF(size.Width / 2, size.Height / 2);
            PointF p1 = PointF.Subtract(location, offset);
            rect = new RectangleF(p1, size);
        }

        private void init()
        {
            bCenterPivot = true;
            initRectangle();
            setLineColor(Color.Purple);
        }

        public sRectangleEmpty()
        {
            size = new SizeF(width, height);
            init();
        }

        public sRectangleEmpty(PointF p)
            : base(p)
        {
            size = new SizeF(width, height);
            init();
        }

        public SizeF getSize()
        {
            return (size);
        }

        public void setSize(float value)
        {
            size = new SizeF(value, value);
            initRectangle();
        }

        public void setSize(float W, float H)
        {
            width = W;
            height = H;
            size = new SizeF(width, height);
            initRectangle();
        }

        public virtual void Draw(Graphics g)
        {
            

            if (bOutLine)
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
        }




    }
}

SuggestionRe: Draw a Line within a class and inheritance Pin
Richard MacCutchan18-Apr-14 22:04
mveRichard MacCutchan18-Apr-14 22:04 
QuestionPartial Snippet Pin
Mycroft Holmes18-Apr-14 16:30
professionalMycroft Holmes18-Apr-14 16:30 
AnswerRe: Partial Snippet Pin
Richard MacCutchan18-Apr-14 21:59
mveRichard MacCutchan18-Apr-14 21:59 
GeneralRe: Partial Snippet Pin
Mycroft Holmes19-Apr-14 2:38
professionalMycroft Holmes19-Apr-14 2:38 
AnswerRe: Partial Snippet Pin
OriginalGriff19-Apr-14 4:31
mveOriginalGriff19-Apr-14 4:31 
Questiona concept I'm trying to build Pin
solo918-Apr-14 15:07
solo918-Apr-14 15:07 
GeneralRe: a concept I'm trying to build Pin
Richard MacCutchan18-Apr-14 21:57
mveRichard MacCutchan18-Apr-14 21:57 
Questioni want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Member 1061806718-Apr-14 12:12
Member 1061806718-Apr-14 12:12 
AnswerRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Richard Andrew x6418-Apr-14 12:19
professionalRichard Andrew x6418-Apr-14 12:19 
GeneralRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Member 1061806718-Apr-14 12:40
Member 1061806718-Apr-14 12:40 
GeneralRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Richard Andrew x6418-Apr-14 12:54
professionalRichard Andrew x6418-Apr-14 12:54 
QuestionProperty with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:09
Matt U.18-Apr-14 8:09 
AnswerRe: Property with "get" only, or a separate method? Pin
OriginalGriff18-Apr-14 8:15
mveOriginalGriff18-Apr-14 8:15 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:16
Matt U.18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
OriginalGriff18-Apr-14 8:32
mveOriginalGriff18-Apr-14 8:32 
AnswerRe: Property with "get" only, or a separate method? Pin
Ravi Bhavnani18-Apr-14 8:16
professionalRavi Bhavnani18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:19
Matt U.18-Apr-14 8:19 

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.