c# 绘图 根据坐标得到字符

c# 绘图 根据坐标得到字符,第1张

既然你已经知道GetCharFromPosition方法,就说明你尽量想往该方法上靠。

那么你使用的是向Rectangle中写字符,Rectangle的类没有TextBox的类强大,所以没有现成的方法,而我们又没有GetCharFromPosition的源码。

所以最佳办法就是你在向Rectangle中写字符的时候,同时也向一个跟Rectangle同样的坐标属性的TextBox中,按照同样的格式写入一个同样的字符串。

使改TextBox作为Rectangle的一个高级模拟。

你可以让该TextBox不显示,然后查找字符串的时候就直接调用TextBox的GetCharFromPosition方法,就可以得到,这是最好的方法了。

模拟代码如下:

int Rectangle_X = 0;

int Rectangle_Y = 0;

int Rectangle_W = 100;

int Rectangle_H = 200;

StringFormat sf = new StringFormat(StringFormatGenericTypographic);

sfFormatFlags = StringFormatFlagsNoWrap;

eGraphicsDrawString(thisText, thisFont, BrushesBlack, new Rectangle(Rectangle_X, Rectangle_Y, Rectangle_W, Rectangle_H), sf);

TextBox t = new TextBox();

Point p = new Point(Rectangle_X, Rectangle_Y);

tLocation = p;

tHeight = Rectangle_H;//该设置本例无用,因为对于TextBox来说,控件大小是由字体大小决定的

tWidth = Rectangle_W;

tFont = thisFont;

thisControlsAdd(t);//如果是窗体程序想看见该TextBox。

tText = thisText;

//因为画笔颜色,和版式,默认都是一般的,对Text框StringFormat,Brushes就不需要设置了。

Point charPoint = new Point(30, 30);

ConsoleWriteLine(tGetCharFromPosition(charPoint));

import matplotlibpyplot as plt  

import random

x1 = list(range(10))

y1 = [randomrandint(0,10) for i in range(10)]  

pltplot(x1, y1,  color='r',markerfacecolor='blue',marker='o')  

for a, b in zip(x1, y1):  

    plttext(a, b, (a,b),ha='center', va='bottom', fontsize=10)  

pltlegend()  

pltshow()

//这个问题其实不难,可以用数学公式进行推导,然后用编程的形式写出来。

//在这里需要注意的是精度问题,下面代码采用浮点数形式。

//获取分点坐标

CPoint GetPoint(CPoint pt1,CPoint pt2,CPoint &pt3,int l)

{

double k,m,m2,k2,x;

k2=k=100000(pt2y-pt1y)/(pt2x-pt1x);

m=sqrt(100000pow(l,2)/(pow(k,2)+1));

m2=sqrt(100000pow(l/32,2)/(pow(k,2)+1));

CPoint pt,ppt;

if(k<0)k=-1k;

if(pt2x<pt1x)

{

ptx=(int)(pt2x+m);

pptx=(int)(pt2x+m2);

}

else

{

ptx=(int)(pt2x-m);

pptx=(int)(pt2x-m2);

}

if(pt2y<pt1y)

{

pty=(int)(k  m) + pt2y;

ppty=(int)(k  m2) + pt2y;

}

else

{

pty=pt2y-(int)(k  m);

ppty=pt2y-(int)(k  m2);

}

k2=-1/k2;

m=sqrt(100000pow(l/4,2)/(pow(k2,2)+1));

if(pt2y<pt1y)

x=ptx+m;

else

x=ptx-m;

pt3y=(int)(k2  (x-ptx)+pty);

pt3x=(int)x;

return ppt;

}

以上就是关于c# 绘图 根据坐标得到字符全部的内容,包括:c# 绘图 根据坐标得到字符、Python使用matplotlib绘图,如何在绘图结果上显示每个点的坐标、如何求直线上和第二个端点距离为m的点的坐标,VC绘图,直线坐标是已知的。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9474983.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存