我試圖設置一個Line類的代碼,除了DefaultLineThickness以外,還有它自己的厚度。盡我所能使用g.DrawLine(Pens.Black,25,40,126,126);它需要在它自己的類中,並且繼承了我已經完成的其他形狀。我發現這個話題最接近我的問題,但它在XAML和其他地方,它只是簡單的g.DrawLine在一個類中繪製直線和厚度:方法組/ OverLoad問題
http://www.c-sharpcorner.com/uploadfile/mahesh/line-in-wpf/
試圖讓粗自行車出來的圓形,方形和線條。
*編輯 經過足夠多的時間玩耍,我在我的目標邊緣。我唯一的問題是,經過我插上一切並設置行厚度爲x-數,它給我一個錯誤,它無法分配,因爲一個「方法組」
Form1的代碼
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;
LineOne l1 = new LineOne(new PointF(50, 40));
l1.setFilledState(false);
l1.setLineColor(Color.Black);
l1.setLineThickness = (6);
//cannot assign to 'setLineThickness' because it is a method group'
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)
{
}
}
}
數量
的線路編碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Bicycle
{
class LineOne : sRectangle
{
private void setDrawingAttributes()
{
const int lenght = 10;
Pen SmallPen = new Pen(Brushes.DeepSkyBlue);
SmallPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
PointF p1 = PointF.Add(location, new Size(-lenght/2, 0));
}
private void init()
{
setDrawingAttributes();
}
public LineOne()
{
init();
}
public LineOne(PointF p)
: base(p)
{
init();
}
public override void Draw(Graphics g)
{
g.DrawEllipse(pen, rect);
}
}
}
形狀代碼
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;
}
}
}
啊好的感謝得到它的工作,同時我注意到我犯了我的行代碼g.DrawEllipse(鋼筆,矩形)的錯誤;而不是if(bOutLine)g.DrawLine(pen,rect);類似於我重寫代碼來強制我的圓圈成爲一個圓圈,我想強制一條線被繪製。我不知道在繪製圓圈時它是如何工作的,但是當我試圖畫出一條線時,它表示'沒有超出方格線的方法,需要兩個參數。 – user3550796