vb.net 如何编写一个程序,能自由创建控件(比如说创建textbox),就像设计时一样
展开全部
Dim Mouse_X, Mouse_Y As Integer, Mouse_ZF As New PictureBox
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_X = e.X
Mouse_Y = e.Y
Mouse_ZF.Location = New Point(e.X - 1, e.Y - 1)
Mouse_ZF.Size = New Size(0, 0)
Mouse_ZF.BorderStyle = BorderStyle.FixedSingle
Mouse_ZF.BackColor = Color.Silver
Mouse_ZF.Visible = True
Mouse_ZF.Name = "ZF"
Me.Controls.Add(Mouse_ZF)
Else
Mouse_X = 0
Mouse_Y = 0
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_ZF.Size = New Size(e.X - Mouse_X, e.Y - Mouse_Y)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_ZF.Visible = False
Dim TB As New TextBox
TB.Location = New Point(Mouse_X + 1, Mouse_Y + 1)
TB.Multiline = True
TB.Size = Mouse_ZF.Size
Me.Controls.Remove(Me.Controls.Item("ZF"))
Me.Controls.Add(TB)
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_X = e.X
Mouse_Y = e.Y
Mouse_ZF.Location = New Point(e.X - 1, e.Y - 1)
Mouse_ZF.Size = New Size(0, 0)
Mouse_ZF.BorderStyle = BorderStyle.FixedSingle
Mouse_ZF.BackColor = Color.Silver
Mouse_ZF.Visible = True
Mouse_ZF.Name = "ZF"
Me.Controls.Add(Mouse_ZF)
Else
Mouse_X = 0
Mouse_Y = 0
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_ZF.Size = New Size(e.X - Mouse_X, e.Y - Mouse_Y)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
Mouse_ZF.Visible = False
Dim TB As New TextBox
TB.Location = New Point(Mouse_X + 1, Mouse_Y + 1)
TB.Multiline = True
TB.Size = Mouse_ZF.Size
Me.Controls.Remove(Me.Controls.Item("ZF"))
Me.Controls.Add(TB)
End If
End Sub
展开全部
dim f New textbox
f = New textbox
f.Location = New Point(左右位置, 上下位置)
f.Size = New Size(长, 宽)
f.Visible = True
Me.Controls.Add(f)
这是添加控件的代码
f = New textbox
f.Location = New Point(左右位置, 上下位置)
f.Size = New Size(长, 宽)
f.Visible = True
Me.Controls.Add(f)
这是添加控件的代码
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
讲清楚一点
更多追问追答
追问
我就拿textbox举例吧。
设计窗体时,你是不是点了一下texbox的按钮,然后在窗体上进行拖动来创建一个textbox?然后,我想让用户点一下button1,便可以使用户在窗体上拖动,来创建textbox。
追答
我想声明一下,你的意思是不是点按钮后,在窗口上建立一个textbox
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询