社区
C++ Builder
帖子详情
画线的问题
茹果伱在
2011-03-23 08:47:56
我要在PaintBox上面画线,用moveto和lianto怎么化成虚线,请帮我写下具体代码,还有当我鼠标点下的时候,茹果鼠标所在的坐标和直线的距离(这个距离自己算)小于一定值,就显示成虚线,以证明选中了,茹果是点在线的端点,就显示成虚线的框框,怎么实现啊?
...全文
110
6
打赏
收藏
画线的问题
我要在PaintBox上面画线,用moveto和lianto怎么化成虚线,请帮我写下具体代码,还有当我鼠标点下的时候,茹果鼠标所在的坐标和直线的距离(这个距离自己算)小于一定值,就显示成虚线,以证明选中了,茹果是点在线的端点,就显示成虚线的框框,怎么实现啊?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
我不懂电脑
2011-03-23
打赏
举报
回复
建议你用addflow很简单。
画虚线只要设置TPen->Style
void __fastcall TForm1::FormActivate(TObject *Sender)
{
WindowState = wsMaximized;
Timer1->Interval = 50;
randomize();
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
x = random(Screen->Width - 10);
y = random(Screen->Height - 10);
Canvas->Pen->Color = (Graphics::TColor) random(65535);
switch (random(5))
{
case 0: Canvas->Pen->Style = psSolid; break;
case 1: Canvas->Pen->Style = psDash; break;
case 2: Canvas->Pen->Style = psDot; break;
case 3: Canvas->Pen->Style = psDashDot; break;
case 4: Canvas->Pen->Style = psDashDotDot; break;
}
Canvas->Rectangle(x, y, x + random(400), y + random(400));
}
xjq2003
2011-03-23
打赏
举报
回复
PaintBox1->Canvas->Pen->Width = 2;
//2改大一些?
PaintBox1->Canvas->Pen->Style = psInsideFrame;
//是不是psInsideFrame;类型的问题啊
茹果伱在
2011-03-23
打赏
举报
回复
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
int style = -1, a1=200, b1=60, a2=100, b2=60;
int oldx, oldy, newx, newy;
class lines
{
public:
int x1, y1, x2, y2;
lines(int a1, int b1, int a2, int b2)
{
x1 = a1;
y1 = b1;
x2 = a2;
y2 = b2;
}
};
void write(TPaintBox *Sender, int a1, int b1, int a2, int b2)
{
Sender->Canvas->MoveTo(a1, b1);
Sender->Canvas->LineTo(a2, b2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
lines a(a1, b1, a2, b2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
PaintBox1->Canvas->Pen->Style = psInsideFrame;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
oldx = X;
oldy = Y;
lines a(a1, b1, a2, b2);
if(sqrt(pow((X-a.x1), 2) + pow((Y-a.y1), 2)) <= 2)//点在(x1,y1)
{
style = 1;
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
else
if(sqrt(pow((X-a.x2), 2) + pow((Y-a.y2), 2)) <= 2)//点在(x2,y2)
{
style = 2;
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
else
if((a.x1 == a.x2)&&(((Y >= a.y1)&&(Y <= a.y2))||((Y <= a.y1)&&(Y >= a.y2)))//与y轴平行
&&(abs(X-a.x1) < 10))
{
style = 0;
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
else
if((a.y1 == a.y2)&&(((X >= a.x1)&&(X <= a.x2))||((X<= a.x1)&&(X >= a.x2))) //与X轴平行
&&(abs(Y-a.y1) < 10))
{
style = 0;
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
else
if(((X >= a.x1)&&(X <= a.x2)||(X<= a.x1)&&(X >= a.x2))
&&((Y >= a.y1)&&(Y <= a.y2)||((Y <= a.y1)&&(Y >= a.y2)))
&&(abs((X*(a.y2-a.y1)+Y*(a.x1-a.x2)-a.x1*a.y2+a.y1*a.x2))/sqrt(pow(X, 2)+pow(Y, 2))) < 5)
{
style = 0;
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
}
else
style = 4;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
newx = X;
newy = Y;
lines a(a1, b1, a2, b2);
if(style == 1)
{
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
write(PaintBox1, X, Y, a.x2, a.y2);
a1 = X; //新的 起点坐标
b1 = Y;
}
else
if(style == 2)
{
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
write(PaintBox1, a.x1, a.y1, X, Y);
a2 = X; //新的 起点坐标
b2 = Y;
}
else
if(style == 0)
{
PaintBox1->Canvas->Pen->Color = Form1->Color; //画笔颜色和Form原色一样,起到橡皮差的作用
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
write(PaintBox1, a.x1+(newx-oldx), a.y1+(newy-oldy), a.x2+(newx-oldx), a.y2+(newy-oldy));
a1 = a.x1+(newx-oldx); //新的坐标
b1 = a.y1+(newy-oldy);
a2 = a.x2+(newx-oldx);
b2 = a.y2+(newy-oldy);
}
style = -1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ShowMessage(IntToStr(style));
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
lines a(a1, b1, a2, b2);
if(style == 1)
{
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
write(PaintBox1, X, Y, a.x2, a.y2);
a1 = X;
b1 = Y;
}
else
if(style == 2)
{
PaintBox1->Canvas->Pen->Color = Form1->Color;
write(PaintBox1, a.x1, a.y1, a.x2, a.y2);
PaintBox1->Canvas->Pen->Color = clRed;
PaintBox1->Canvas->Pen->Width = 2;
write(PaintBox1, a.x1, a.y1, X, Y);
a2 = X; //新的 起点坐标
b2 = Y;
}
}
//---------------------------------------------------------------------------
xjq2003
2011-03-23
打赏
举报
回复
代码发来,我帮你测试一下
茹果伱在
2011-03-23
打赏
举报
回复
怎么没人啊 急。。
茹果伱在
2011-03-23
打赏
举报
回复
来人帮帮忙哦
通达信指标公式源码 中枢自动划线 主图源码.doc
通达信作为国内知名的证券分析软件,其强大的自定义指标公式功能深受广大投资者和分析师的...此外,源码的优化和升级也是投资者需要持续关注的
问题
,因为金融市场在不断变化,只有不断更新的分析工具才能保持竞争力。
原创Matlab鼠标取点在不同坐标轴之间
画线
-不同坐标轴之间选点划线.rar
原创Matlab鼠标取点在不同坐标轴之间
画线
-不同坐标轴之间选点划线.rar 看到有会员提出,如何实现用鼠标在GUI上的两个坐标轴上选点,然后连线的
问题
。于是花了点时间研究下,编写了这个程序。 由于MATLAB提供的...
单线
画线
机.zip机械设计毕业设计
首先,
画线
机的核心部分是其工作机构,通常包括驱动装置、传动系统和划线装置。驱动装置为整个机器提供动力,可能采用电动机或者气压马达等;传动系统则将动力传递至划线装置,确保运动的精确性;划线装置则负责在...
3_get_line.zip_C语言_k60_划线
4. 划线算法:为了在屏幕上
画线
,你可以采用Bresenham算法或者其他优化过的算法。Bresenham算法是一种在离散像素阵列上近似
画线
的算法,它避免了浮点运算,适合资源有限的嵌入式系统。 5. 用户输入:如果要根据用户...
行业文档-设计装置-拉链布带划线笔.zip
这份名为“拉链布带划线笔.pdf”的文档很可能包含了详细的使用指南、维护方法、常见
问题
及解决方案等内容,对于理解拉链布带划线笔的工作原理和优化使用方式大有裨益。无论是初学者还是经验丰富的专业人士,都应深入...
C++ Builder
13,871
社区成员
102,694
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章