用GDI+写了个绘制带箭头直线的方法,代码如下:
private void DrawArrow(Point pStartPoint, Point pEndPoint)
{
Graphics vGraph = xtraScrollableControl1.CreateGraphics();
vGraph.Clear(Color.White);
Pen vPen = new Pen(Color.Black, 2);
vPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
vPen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3);
vGraph.DrawLine(vPen, pStartPoint, pEndPoint);
}为什么在xtraScrollableControl1没有显示出来?求高手解决!!感谢!
private void DrawArrow(Point pStartPoint, Point pEndPoint)
{
Graphics vGraph = xtraScrollableControl1.CreateGraphics();
vGraph.Clear(Color.White);
Pen vPen = new Pen(Color.Black, 2);
vPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
vPen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3);
vGraph.DrawLine(vPen, pStartPoint, pEndPoint);
}为什么在xtraScrollableControl1没有显示出来?求高手解决!!感谢!
自己创建一个CreateGraphics()不行的吗?网上怎么大多是这么写的?
{
Brush br = new SolidBrush(Color.Red);
Pen p = new Pen(br);
Graphics gf =this.CreateGraphics();
Point p1=new Point(10,100);
Point p2=new Point(60,100);
Point p3 = new Point(55, 95);
Point p4 = new Point(60, 100);
Point p5 = new Point(55, 105);
Point p6 = new Point(60, 100); gf.DrawLine(p,p1,p2);
gf.DrawLine(p, p3, p4);
gf.DrawLine(p, p5, p6);
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TESTQQ
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
Graphics g = null;
Pen pen = new Pen(Color.Red);
float x1 = 0f;
float y1 = 0f;
float x2 = 0f;
float y2 = 0f;
private void Form4_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawLine(pen, 100, 100, 100+x1,100+ y1);
g.DrawLine(pen, 100 + x1, 100 + y1, 100 + x1, 100 + y1+50);
g.DrawLine(pen, 100, 100, 100, 100 + 50);
g.DrawLine(pen, 100, 150, 100 + x1, 100 + y1 + 50);
} private void Form4_Load(object sender, EventArgs e)
{
g = this.CreateGraphics();
}
float angle = 0f;
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
} private void timer1_Tick(object sender, EventArgs e)
{
double oldWidth = (double)100;
//角度转弧度 角度*PI/180
double theta = angle * Math.PI / 180;
double locked_theta = theta;
double adjacentTop = Math.Cos(locked_theta) * 50; //X
//底边长
double oppositeTop = Math.Sin(locked_theta) * 50; //Y
y1 = (float)oppositeTop;
x1 = (float)adjacentTop;
this.Invalidate();
this.Text = angle.ToString() + "y1:" + y1 + ",x1:" + x1;
angle = angle + 1f;
}
}
}
哥的这个直线比较有趣吧
请问你的两个Point参数是否正确,还有一点就是你通过CreateGraphics()方式去画的话,在代码最后应该调用该控件的Invalidate()方法,使控件重绘,估计你是没有添加这个方法吧,我刚开始学GDI+的时候也遇到这样的问题,呵呵!希望可以帮到你!