Solved

Graphics

Posted on 2002-06-03
5
158 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
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now