社区
C++ Builder
帖子详情
画线的问题
茹果伱在
2011-03-23 08:47:56
我要在PaintBox上面画线,用moveto和lianto怎么化成虚线,请帮我写下具体代码,还有当我鼠标点下的时候,茹果鼠标所在的坐标和直线的距离(这个距离自己算)小于一定值,就显示成虚线,以证明选中了,茹果是点在线的端点,就显示成虚线的框框,怎么实现啊?
...全文
107
6
打赏
收藏
画线的问题
我要在PaintBox上面画线,用moveto和lianto怎么化成虚线,请帮我写下具体代码,还有当我鼠标点下的时候,茹果鼠标所在的坐标和直线的距离(这个距离自己算)小于一定值,就显示成虚线,以证明选中了,茹果是点在线的端点,就显示成虚线的框框,怎么实现啊?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
打赏
举报
回复
来人帮帮忙哦
59.(leaflet篇)leaflet动态
画线
.zip
下载如有
问题
,可私信博主。下载前建议先查看博客内容,其地址为:https://blog.csdn.net/QQ98281642/article/details/122121747
原创Matlab鼠标取点在不同坐标轴之间
画线
-不同坐标轴之间选点划线.rar
原创Matlab鼠标取点在不同坐标轴之间
画线
-不同坐标轴之间选点划线.rar 看到有会员提出,如何实现用鼠标在GUI上的两个坐标轴上选点,然后连线的
问题
。于是花了点时间研究下,编写了这个程序。 由于MATLAB提供的...
Python游戏基础-使用tkinter模块画高级图形
具体包括:创建一个可以点的按钮、使用具名参数、创建一个画图用的画布、
画线
、画正方形或矩形、画圆弧、画多边形、显示文字、创建基本的动画、对键盘事件的响应、随机函数、设置图形颜色、显示图片。学会这些基础...
算法复杂度作业2
shell network perl sed awk 算法 java 数据结构
测量工具.zip
在Arcgis中实现测量长度和面积,里面功能可以实现在arcgis上实现橡皮筋样式的划线,同时中键可以移动底图不影响
画线
,没有利用arcgis自带的划线工具,而是记录点坐标实时划线,同时中键可以移动底图,是很好参考程序...
C++ Builder
13,825
社区成员
102,679
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章