求助,在类里如何用程序指令画矩形框

xaping1980 2011-05-17 02:12:55
我是一个新手,请教各位高手。
想请问如何在Class里用指令画一个矩形框

以下是我类的内容,程序做了画两个文本框和一个按钮,功能,我还想继续,画两个矩形框,但不知道如何在类里面实现???
Public Class OpSet
Private startBox, stopBox As New TextBox, changeButton As New Button, Rectangle1, Rectangle2 As New Rectangle
Private graphicsFun As Graphics, BrushColor As New SolidBrush(Color.Blue)


Sub New(ByVal frm As Form, ByVal x As Integer, ByVal y As Integer)

startBox.Location = New Point(x, y)
stopBox.Location = New Point(x + startBox.Size.Width + 50, y)

changeButton.Location = New Point(stopBox.Location.X + stopBox.Size.Width + 50, y)
changeButton.Text = "confirm"

graphicsFun = frm.CreateGraphics
graphicsFun.FillRectangle(BrushColor, x, changeButton.Location.Y + changeButton.Width + 50, 200, 10)


AddHandler changeButton.Click, AddressOf changeButton_Click
frm.Controls.AddRange({startBox, stopBox, changeButton})


End Sub

Private Sub changeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim startNum, stopNum As Integer

If (Not Integer.TryParse(startBox.Text, startNum)) OrElse startNum < 0 OrElse startNum > 100 Then
MessageBox.Show("Invalid start value")
Exit Sub
End If

If (Not Integer.TryParse(stopBox.Text, stopNum)) OrElse stopNum < 0 OrElse stopNum > 100 Then
MessageBox.Show("Invalid stop value")
Exit Sub
End If
MessageBox.Show("New values are: start = " & startNum.ToString & ", stop = " & stopNum.ToString)
End Sub
End Class

以下是我主画面的内容,在屏幕上添加了两组上面的类
Public Class Form1
Private opsets As New List(Of OpSet)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
opsets.Add(New OpSet(Me, 100, 300))
opsets.Add(New OpSet(Me, 100, 400))

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
End Class


还有个问题就是,如上程序,在屏幕上创建了4个文本框,这4个文本框的地址是什么?假如我在Form2上画了另一个文本框,想让Form2上的这个文本框的内容等于Form1文本框输入的数值,那么Form2 Load事件我就要写
TextBox1.Text=?????‘这个值希望就是Form1里某一个文本框的输入值,该怎么写。
谢谢
...全文
130 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xaping1980 2011-05-17
  • 打赏
  • 举报
回复
谢谢
是画出来了,需要在Form1_Paint里调用即可。

但是文本框输入地址问题还没有解决。
当程序运行时,我往文本框里写数字,这个文本框里的数字内容如何使用在其它地方?就是类里的程序changeButton_Clik的startBox.Text startNum值如何在其它程序段里表达出来
兔子-顾问 2011-05-17
  • 打赏
  • 举报
回复
你这本来就是在类中实现了啊。
稍微了解一下绘图的基础。CreateGraphics是根据给定控件句柄创建GDI+绘图句柄,然后绘制的,如果窗体没创建好,刚new好,没Show/create的话,获取的绘图对象是无效的,即便合适的时候获取,你绘制的也会在控件被遮挡等使得控件“无效”后,被刷新擦除。
你可以绘制到一个位图上,然后设置控件的background属性为你的位图。

16,720

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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