|
-
May 31st, 2005, 01:23 PM
#1
drawing controls at run-time
hey guys, i got 2 problems,
1. i want the user to click on a form and the app. must draw a GroupBox at that location with a Label inside it.
All that shows on screen is the GroupBox...... i am bringing the label to the front but its still not showing.
The code I tried out is as follows:
Code:
Private l As New Label
Private g As New GroupBox
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
Dim q As System.Drawing.Point
q.X = e.X
q.Y = e.Y
g.Location = q
g.Text = ""
Me.Controls.Add(g)
l.Parent = g
l.Dock = DockStyle.Fill
l.Text = Me.TextBox1.Text
l.TextAlign = ContentAlignment.MiddleCenter
l.BringToFront()
l.Visible = True
Me.Controls.Add(l)
End Sub
2. How can I draw a line from one control to another? I would like the user to click on 2 controls...... a line will be created from the edge of one to the other.
Thanks in advance for your advice
-
May 31st, 2005, 01:51 PM
#2
Re: drawing controls at run-time
You need to add
g.Controls.Add(l)
-
June 3rd, 2005, 02:36 PM
#3
Re: drawing controls at run-time
ok thanks..... u were of great help.
Re question 1........ the app is now drawing the 2 controls on the form. but when the user clicks on the form the second time...... the controls created first are removed and added again at the new location.
what i want is....... that the first controls are left where they are....... and others are placed at the second or third click position.
i think id have to fix the declaration of the controls!! Am i right?
What should i do?
-
June 3rd, 2005, 04:02 PM
#4
Re: drawing controls at run-time
Create g inside MouseDown() event.
Good Luck,
-Cool Bizs
-
June 3rd, 2005, 06:29 PM
#5
Re: drawing controls at run-time
all the code is already under the mouse down event
-
June 3rd, 2005, 06:35 PM
#6
Re: drawing controls at run-time
oh sorry..... i misunderstood...... i did as u said and declared the label under mouse down event too and its working great.
here is the code:
Code:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
Dim l As New Label
Dim g As New GroupBox
Dim q As New System.Drawing.Point
q.X = e.X
q.Y = e.Y
g.Location = q
g.Text = ""
Me.Controls.Add(g)
l.Parent = g
l.Dock = DockStyle.Fill
l.Text = Me.TextBox1.Text
l.TextAlign = ContentAlignment.MiddleCenter
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|