控制系统中的VB编程

devile55 2016-10-23 02:13:34

如图,本人学VB不久,想问上图坐标系是怎么编程实现的?
...全文
1843 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-04-05
  • 打赏
  • 举报
回复
循环 和 展开后循环 各有各的 优缺点。
zdingyun 2017-04-03
  • 打赏
  • 举报
回复
引用 7 楼 Chen8013 的回复:
楼上的,画那些“网格线”,不能用循环吗?
可以用循环,懒得改了。
vansoft 2017-04-02
  • 打赏
  • 举报
回复
全自己画 先建立一个坐标系,然后就按坐标往上画好了。
舉杯邀明月 2017-04-02
  • 打赏
  • 举报
回复
楼上的,画那些“网格线”,不能用循环吗?
zdingyun 2017-04-02
  • 打赏
  • 举报
回复
可以参考以下代码修改实现绘制:
Option Explicit
    Dim i As Long
    Dim j As Long
    Dim X As Long
    Dim Y As Long
    Dim fnt As Long
    Dim txt As Variant
    Dim dd As Variant
    Dim xx
    Dim yy
    Dim colvb
    Dim wp
    
Public Function xp(colvb As Variant, xx As Variant, yy As Variant, txt As Variant)
    Picture1.ForeColor = colvb
    Picture1.CurrentX = xx
    Picture1.CurrentY = yy
    Picture1.Print txt '
End Function

Private Sub Form_Activate()
    colvb = vbWhite
    xx = 100
    yy = 150
    txt = "℃"
    wp = xp(colvb, xx, yy, txt)
    yy = 350
    txt = "150"
    wp = xp(colvb, xx, yy, txt)
    xx = 200
    yy = 1350
    txt = "100"
    wp = xp(colvb, xx, yy, txt)
    yy = 2350
    txt = " 50"
    wp = xp(colvb, xx, yy, txt)
    xx = 300
    yy = 3350
    txt = "0"
    wp = xp(colvb, xx, yy, txt)
    xx = 100
    yy = 4350
    txt = "-50"
    wp = xp(colvb, xx, yy, txt)
    xx = 0
    yy = 5350
    txt = "-100"
    wp = xp(colvb, xx, yy, txt)
    xx = 0
    yy = 6350
    txt = "-150"
    wp = xp(colvb, xx, yy, txt)
    xx = 10800 + 100
    yy = 150
    txt = "℃"
    wp = xp(colvb, xx, yy, txt)
    yy = 350
    txt = "150"
    wp = xp(colvb, xx, yy, txt)
    xx = 10800 + 200
    yy = 1350
    txt = "100"
    wp = xp(colvb, xx, yy, txt)
    yy = 2350
    txt = " 50"
    wp = xp(colvb, xx, yy, txt)
    yy = 3350
    xx = 10800 + 300
    txt = "0"
    wp = xp(colvb, xx, yy, txt)
    xx = 10800 + 100
    yy = 4350
    txt = "-50"
    wp = xp(colvb, xx, yy, txt)
    xx = 10800 + 0
    yy = 5350
    txt = "-100"
    wp = xp(colvb, xx, yy, txt)
    yy = 6350
    txt = "-150"
    wp = xp(colvb, xx, yy, txt)
    '真空坐标
    colvb = vbRed
    xx = 11400
    yy = 150
    txt = "Pa"
    wp = xp(colvb, xx, yy, txt)
    yy = 350
    txt = "10000"
    wp = xp(colvb, xx, yy, txt)
    xx = 11500
    yy = 1850
    txt = "1000"
    wp = xp(colvb, xx, yy, txt)
    yy = 3350
    xx = 11600
    txt = "100"
    wp = xp(colvb, xx, yy, txt)
    xx = 11700
    yy = 4850
    txt = "10"
    wp = xp(colvb, xx, yy, txt)
    xx = 11500
    yy = 6350
    txt = "  1"
    wp = xp(colvb, xx, yy, txt)
    xx = 500
    yy = 150
    txt = "Pa"
    wp = xp(colvb, xx, yy, txt)
    yy = 150
    xx = 2200
    txt = "6hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 4000
    txt = "12hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 5800
    txt = "18hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 7600
    txt = "24hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 9400
    txt = "30hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 13000
    txt = "42hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 14800
    txt = "48hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 16600
    txt = "54hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 18400
    txt = "60hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 20200
    txt = "66hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 22000
    txt = "72hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 23800
    txt = "78hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 25600
    txt = "84hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 27400
    txt = "90hr"
    wp = xp(colvb, xx, yy, txt)
    xx = 29200
    txt = "96hr"
    wp = xp(colvb, xx, yy, txt)
    yy = 350
    txt = "10000"
    wp = xp(colvb, xx, yy, txt)
    xx = 600
    yy = 1850
    txt = "1000"
    wp = xp(colvb, xx, yy, txt)
    yy = 3350
    xx = 600
    txt = "100"
    wp = xp(colvb, xx, yy, txt)
    xx = 700
    yy = 4850
    txt = "10"
    wp = xp(colvb, xx, yy, txt)
    xx = 600
    yy = 6350
    txt = "1"
    wp = xp(colvb, xx, yy, txt)
    xx = 22100
    yy = 350
    txt = "10000"
    wp = xp(colvb, xx, yy, txt)
    yy = 1850
    txt = "1000"
    wp = xp(colvb, xx, yy, txt)
    yy = 3350
    txt = "100"
    wp = xp(colvb, xx, yy, txt)
    yy = 4850
    txt = " 10"
    wp = xp(colvb, xx, yy, txt)
    yy = 6350
    txt = "  1"
    wp = xp(colvb, xx, yy, txt)
    '画格
    'Picture1.ForeColor = vbWhite
    'Picture1.Line (450, 700)-(500, 700)
    'Picture1.Line (450, 1000)-(500, 1000)
    'Picture1.Line (450, 1300)-(500, 1300)
    'Picture1.Line (450, 1600)-(500, 1600)
    Picture1.ForeColor = vbRed
    Picture1.Line (500, 1900)-(29300, 1900)
    Picture1.Line (500, 4900)-(29300, 4900)
    Picture1.Line (500, 566.7)-(550, 566.7)
    Picture1.Line (500, 733.3)-(550, 733.3)
    Picture1.Line (500, 900)-(550, 900)
    Picture1.Line (500, 1066.7)-(550, 1066.7)
    Picture1.Line (500, 1233.3)-(550, 1233.3)
    Picture1.Line (500, 1400)-(550, 1400)
    Picture1.Line (500, 1566.7)-(550, 1566.7)
    Picture1.Line (500, 1733.3)-(550, 1733.3)
    Picture1.Line (500, 2066.7)-(550, 2066.7)
    Picture1.Line (500, 2233.3)-(550, 2233.3)
    Picture1.Line (500, 2400)-(550, 2400)
    Picture1.Line (500, 2566.7)-(550, 2566.7)
    Picture1.Line (500, 2733.3)-(550, 2733.3)
    Picture1.Line (500, 2900)-(550, 2900)
    Picture1.Line (500, 3066.7)-(550, 3066.7)
    Picture1.Line (500, 3233.3)-(550, 3233.3)
    Picture1.Line (500, 3566.7)-(550, 3566.7)
    Picture1.Line (500, 3733.3)-(550, 3733.3)
    Picture1.Line (500, 3900)-(550, 3900)
    Picture1.Line (500, 4066.7)-(550, 4066.7)
    Picture1.Line (500, 4233.3)-(550, 4233.3)
    Picture1.Line (500, 4400)-(550, 4400)
    Picture1.Line (500, 4566.7)-(550, 4566.7)
    Picture1.Line (500, 4733.3)-(550, 4733.3)
    Picture1.Line (500, 5066.7)-(550, 5066.7)
    Picture1.Line (500, 5233.3)-(550, 5233.3)
    Picture1.Line (500, 5400)-(550, 5400)
    Picture1.Line (500, 5566.7)-(550, 5566.7)
    Picture1.Line (500, 5733.3)-(550, 5733.3) '000
    Picture1.Line (500, 5900)-(550, 5900)
    Picture1.Line (500, 6066.7)-(550, 6066.7)
    Picture1.Line (500, 6233.3)-(550, 6233.3)
    Picture1.ForeColor = vbWhite
    Picture1.Line (450, 400)-(29300, 400)
    Picture1.Line (450, 1400)-(29300, 1400)
    Picture1.Line (450, 2400)-(29300, 2400)
    Picture1.Line (450, 3400)-(29300, 3400)
    Picture1.Line (450, 4400)-(29300, 4400)
    Picture1.Line (450, 5400)-(29300, 5400)
    Picture1.Line (450, 6400)-(29300, 6400)
    For i = 1 To 30
    Picture1.Line (450, 400 + i * 200)-(500, 400 + i * 200)
    Next
    Picture1.Line (500 + 0, 400)-(500 + 0, 6400)
    Picture1.Line (1400 + 0, 400)-(1400 + 0, 6400)
    Picture1.Line (2300 + 0, 400)-(2300 + 0, 6400)
    Picture1.Line (3200 + 0, 400)-(3200 + 0, 6400)
    Picture1.Line (4100 + 0, 400)-(4100 + 0, 6400)
    Picture1.Line (5000 + 0, 400)-(5000 + 0, 6400)
    Picture1.Line (5900 + 0, 400)-(5900 + 0, 6400)
    Picture1.Line (6800 + 0, 400)-(6800 + 0, 6400)
    Picture1.Line (7700 + 0, 400)-(7700 + 0, 6400)
    Picture1.Line (8600 + 0, 400)-(8600 + 0, 6400)
    Picture1.Line (9500 + 0, 400)-(9500 + 0, 6400)
    Picture1.Line (10400 + 0, 400)-(10400 + 0, 6400)
    Picture1.Line (11300, 400)-(11300, 6400)
    Picture1.Line (12200, 400)-(12200, 6400)
    Picture1.Line (13100, 400)-(13100, 6400)
    Picture1.Line (14000, 400)-(14000, 6400)
    Picture1.Line (14900, 400)-(14900, 6400)
    Picture1.Line (15800, 400)-(15800, 6400)
    Picture1.Line (16700, 400)-(16700, 6400)
    Picture1.Line (17600, 400)-(17600, 6400)
    Picture1.Line (18500, 400)-(18500, 6400)
    Picture1.Line (19400, 400)-(19400, 6400)
    Picture1.Line (20300, 400)-(20300, 6400)
    Picture1.Line (21200, 400)-(21200, 6400)
    Picture1.Line (22100, 400)-(22100, 6400)
    Picture1.Line (23000, 400)-(23000, 6400)
    Picture1.Line (23900, 400)-(23900, 6400)
    Picture1.Line (24800, 400)-(24800, 6400) '000
    Picture1.Line (25700, 400)-(25700, 6400) '000
    Picture1.Line (26600, 400)-(26600, 6400) '000
    Picture1.Line (27500, 400)-(27500, 6400) '000
    Picture1.Line (28400, 400)-(28400, 6400) '000
    Picture1.Line (29300, 400)-(29300, 6400)
End Sub

Private Sub Form_Load()
    Picture1.BackColor = vbBlack
End Sub
赵4老师 2016-10-24
  • 打赏
  • 举报
回复
ScaleHeight、ScaleWidth 属性 当使用图形方法或调整控件位置时,返回或设置对象内部的水平 (ScaleWidth) 或垂直 (ScaleHeight) 度量单位。对于 MDIForm 对象,在设计时 是不可用的,并且在运行时是只读的。 语法 object.ScaleHeight [= value] object.ScaleWidth [= value] ScaleHeight 和 ScaleWidth 属性的语法包含下面部分: 部分 描述 Object 对象表达式,其值是“应用于”列表中的一个对象。 Value 一个用来指定水平或垂直度量的数值表达式。 说明 能够使用这些属性来为绘图或打印创建一个自定义的坐标比例尺。例如,语句 ScaleHeight = 100 将改变窗体实际内部高度的度量单位。取代当前高度为 n 个单位(缇、像素、...),高度将变为 100 个自定义单位。因而,50 个单位的距离就是对象的高度/宽度的一半,101 个单位的距离将超出对象 1 个单位。 为了定义基于标准度量单位的比例尺,例如缇、磅、像素、字符、英寸、毫米、或厘米应使用 ScaleMode 属性。 这些属性设置为正值将使坐标从上向下及从左向右增加。它们设置为负值将使坐标从下向上及从右向左增加。 这些属性和相关的 ScaleLeft 与 ScaleTop 属性的使用,可以建立起一个完全的带有正、负坐标的坐标系统。所有这四个 Scale 属性与 ScaleMode 属性按下面的方式进行交互作用: 把其它任何 Scale 属性设置为任何值都将使 ScaleMode 自动地设置为 0。ScaleMode 等于 0 是用户定义。 把 ScaleMode 设置为一个大于 0 的数,将使 ScaleHeight 和 ScaleWidth 的度量单位发生改变,并将 ScaleLeft 和 ScaleTop 设置为 0。另外,CurrentX 和 CurrentY 的设置值将发生改变以反映当前点的新坐标。 也可以在语句中使用 Scale 方法设置 ScaleHeight、ScaleWidth、ScaleLeft 和 ScaleTop 属性。 注意 ScaleHeight 和 ScaleWidth 属性与 Height 和 Width 属性是不一样的。 对于 MDIForm 对象,ScaleHeight 和 ScaleWidth 仅涉及窗体中未被 PictureBox 控件覆盖的区域。在 MDIForm 的 Resize 事件中应避免使用这些属性调整 PictureBox 的大小。
赵4老师 2016-10-24
  • 打赏
  • 举报
回复
Print 方法 在 Immediate 窗口中显示文本。 语法 object.Print [outputlist] Print 方法的语法具有下列对象限定符和部分: 部分 描述 object 必需的。对象表达式,其值为“应用于”列表中的对象。 outputlist 可选的。要打印的表达式或表达式的列表。如果省略,则打印一空白行。 outputlist 参数具有以下语法和部分: {Spc(n) | Tab(n)} expression charpos 部分 描述 Spc(n) 可选的。用来在输出中插入空白字符,这里,n 为要插入的空白字符数。 Tab(n) 可选的。用来将插入点定位在绝对列号上,这里,n 为列号。使用无参数的 Tab(n) 将插入点定位在下一个打印区的起始位置。 expression 可选。要打印的数值表达式或字符串表达式。 charpos 可选。指定下个字符的插入点。使用分号 (;) 直接将插入点定位在上一个被显示的字符之后。使用 Tab(n) 将插入点定位在绝对列号上。使用无参数的 Tab 将插入点定位在下一个打印区的起始位置。如果省略 charpos,则在下一行打印下一字符。 说明 可以用空白或分号来分隔多个表达式。 对系统指定的国别设置,用小数点分隔符将所有打印到 Immediate 视窗的数据正确格式化。关键字要用适用于主应用程序的语言输出。 对于 Boolean 数据,或者打印 True 或者打印 False。根据主机应用程序的地区设置来翻译 True 和 False 关键字。 使用系统能识别的标准短日期格式书写 Date 数据。当日期或时间部件丢失或为零时,只书写已提供的部件。 如果 outputlist 数据是 Empty,则无内容可写。但是,如果 outputlist 数据是 Null,则输出 Null。在输出 Null 关键字时,要把关键字正确翻译出来。 要把错误数据作为 Error errorcode 输出。在输出 Error 关键字时,要把关键字正确翻译出来。 如果在具有缺省显示空间的模块外使用此方法,则需要 object。例如,如果没有指定对象就在标准模块上调用此方法,则将导致错误发生,但是,如果在窗体模块上进行调用,则会在窗体上显示“outputlist”。 注意 因为 Print 方法是按照字符比例进行打印,所以字符数与字符所占据的宽度固定的列的数目无关。例如,像 “W” 这样的宽字母占据的宽度超过一固定列宽,而像 "i" 这样的窄字母占据的宽度则较小。考虑到要使用比平均字符更宽的空间,表列一定要留有足够余地。另外,也可以使用固定间距的字体(像 Courier 字体)来确保每一字符均只占一列。
赵4老师 2016-10-24
  • 打赏
  • 举报
回复
Line 方法 在对象上画直线和矩形。 语法 object.Line [Step] (x1, 1) [Step] (x2, y2), [color], [B][F] Line 方法的语法有以下对象限定符和部分: 部分 描述 object 可选的。 对象表达式,其值为“应用于”列表中的对象。如果object 省略,具有焦点的窗体作为object。 Step 可选的。关键字,指定起点坐标,它们相对于由 CurrentX 和 CurrentY 属性提供的当前图形位置。 (x1, y1) 可选的。Single (单精度浮点数),直线或矩形的起点坐标。ScaleMode 属性决定了使用的度量单位。如果省略,线起始于由 CurrentX 和 CurrentY 指示的位置。 Step 可选的。关键字,指定相对于线的起点的终点坐标。 (x2, y2) 必需的。Single (单精度浮点数),直线或矩形的终点坐标。 color 可选的。Long (长整型数),画线时用的 RGB 颜色。如果它被省略,则使用 ForeColor 属性值。可用 RGB 函数或 QBColor 函数指定颜色。 B 可选的。如果包括,则利用对角坐标画出矩形。 F 可选的。如果使用了 B 选项,则 F 选项规定矩形以矩形边框的颜色填充。不能不用 B 而用 F。如果不用 F 光用 B,则矩形用当前的 FillColor 和 FillStyle 填充。FillStyle 的缺省值为 transparent。 说明 画联结的线时,前一条线的终点就是后一条线的起点。 线的宽度取决于 DrawWidth 属性值。在背景上画线和矩形的方法取决于 DrawMode 和 DrawStyle 属性值。 执行 Line 方法时, CurrentX 和 CurrentY 属性被参数设置为终点。 这个方法不能用于With...End With 语句块。 CurrentX、CurrentY 属性 返回或设置下一次打印或绘图方法的 水平 (CurrentX) 或垂直 (CurrentY) 坐标。设计时不可用。 语法 object.CurrentX [= x] object.CurrentY [= y] CurrentX 和 CurrentY 属性语法包含下面部分: 部分 描述 Object 对象表达式,其值是“应用于”列表中的一个对象。 X 确定水平坐标的数值。 Y 确定垂直坐标的数值。 说明 坐标从对象的左上角开始测量。在对象的左边 CurrentX 属性值为 0,上边的 CurrentY 为 0。坐标以缇为单位表示,或以 ScaleHeight、ScaleWidth、ScaleLeft、ScaleTop 和 ScaleMode 属性定义的度量单位来表示。 用下面的图形方法时,CurrentX 和 CurrentY 的设置值按下述说明改变: 方法 设置 CurrentX, CurrentY 为: Circle 对象的中心。 Cls 0,0。 EndDoc 0,0。 Line 线终点。 NewPage 0,0。 Print 下一个打印位置。 Pset 画出的点。
笨狗先飞 2016-10-24
  • 打赏
  • 举报
回复
自己画图,坐标转换

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧