• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Graphics

I am writing a program, that should dynamically draw a rectangle with a label on it.

For example -  
If I input 3 strings say "Activity1", "Activity2" and "Activity3", thru my first form, then the program should display 3 rectangles labelled "Activity1", "Activity2" and "Activity3" in another form.
Labelled in the sense, rectangle should contain the text at its center
Position of display is immaterial

Please guide me on how I can do this.

Thanks In advance for any help
0
srividyakrishnamurthy
Asked:
srividyakrishnamurthy
1 Solution
 
appariCommented:
sample something like this
new project with two forms form1 and form2.
form1 3 textboxes and one command button. on command1click write the following code


Private Sub Command1_Click()
form2.show
Form2.Line (100, 100)-(100, 500)
Form2.Line (100, 100)-(2500, 100)
Form2.Line (100, 500)-(2500, 500)
Form2.Line (2500, 100)-(2500, 500)

Form2.CurrentX = 200
Form2.CurrentY = 200
Form2.Print Text1

Form2.Line (100, 1000)-(100, 1500)
Form2.Line (100, 1000)-(2500, 1000)
Form2.Line (100, 1500)-(2500, 1500)
Form2.Line (2500, 1000)-(2500, 1500)

Form2.CurrentX = 200
Form2.CurrentY = 1200
Form2.Print Text2


Form2.Line (100, 2000)-(100, 2500)
Form2.Line (100, 2000)-(2500, 2000)
Form2.Line (100, 2500)-(2500, 2500)
Form2.Line (2500, 2000)-(2500, 2500)

Form2.CurrentX = 200
Form2.CurrentY = 2200
Form2.Print Text3

End Sub
0
 
mdouganCommented:
One question might be, once the rectangles are drawn, can the user interact with them?  If so, then simply drawing the rectangles on the form is going to cause problems, as it will make it more difficult to tell when a user has clicked or tried to drag a particular rectangle.

What I have used instead, with good results, is to put a single hidden picturebox on the second form, with border set to single, scalemode set to pixels, and with an index of zero.  You can size the picturebox any size you want it, and move it anywhere on the form that you want it, and you can also create as many new pictureboxes dynamically as you need.  So, in your case, you might have code like this:

In Form1's cmdDraw_Click event:

Load Form2
Form2.picRect(0).Left = 100
Form2.picRect(0).Top = 100
Form2.picRect(0).Height = 100
Form2.picRect(0).Width = 200
Form2.picRect(0).Print "Activity 1"
Form2.picRect(0).Visible = True

Load Form2.picRect(1)
Form2.picRect(1).Left = 100
Form2.picRect(1).Top = 300
Form2.picRect(1).Height = 100
Form2.picRect(1).Width = 200
Form2.picRect(1).Print "Activity 2"
Form2.picRect(1).Visible = True

Load Form2.picRect(2)
Form2.picRect(2).Left = 100
Form2.picRect(2).Top = 500
Form2.picRect(2).Height = 100
Form2.picRect(2).Width = 200
Form2.picRect(2).Print "Activity 3"
Form2.picRect(2).Visible = True

Form2.Show


If you want to position the text within the picture box in exactly the center, it gets a little more complicated.  You would have to take the left property and then add to it 1/2 of the width property to get the center X value, then take the top property and add to it 1/2 the height property to get the center Y value.  Then, you have to figure out how many pixels wide and tall your text is going to be (I think you can use the windows API GetTextMetrics to give you pixel height and width of average characters for a picturebox or whatever), then position the  pictureboxes CurrentX and CurrentY there just before issuing the:

Form2.picRect(2).CurrentX = Form2.picRect(2).Left + (Form2.picRect(2).Width / 2) - 50
Form2.picRect(2).CurrentY = Form2.picRect(2).Top + (Form2.picRect(2).Height/ 2) - 10
Form2.picRect(2).Print "Activity 3"



0
 
mdouganCommented:
Oh, and the reason for using pictureboxes was that then, if the user double-clicks a picturebox or wants to drag it around on the screen, then you have a control (the picRect control array) which will respond to the events and make it much easier to manipulate them.
0
 
Richie_SimonettiIT OperationsCommented:
Hearing...
0
 
MoondancerCommented:
srividyakrishnamurthy ->  You have asked many questions here and fail to update experts who help you and also to close your questions and award points, this is against our Guidelines and not acceptable.

I am in the process of finalizing your old, open questions and ask that you remain active in all of them, provide feedback to the experts who help you and award points.

If you need help, ask us in Community Support with zero point questions, include the QID link.

Moondancer - EE Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now