Solved

Graphics

Posted on 2002-06-03
5
161 Views
Last Modified: 2010-05-02
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
Comment
Question by:srividyakrishnamurthy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Accepted Solution

by:
appari earned 300 total points
ID: 7053359
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
 
LVL 18

Expert Comment

by:mdougan
ID: 7053654
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
 
LVL 18

Expert Comment

by:mdougan
ID: 7053655
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7054323
Hearing...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7054542
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question