Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
Using graphics for thwe first time... help please.
Old
  (#1)
ComputerSmith
Guest
 
Posts: n/a
Default Using graphics for thwe first time... help please. - 06-04-2007, 08:54 AM

Hi all.
I have programmed VB6 apps before, ones that use dropdown listboxes, text
boxes, etc... normal stuff.

I was asked by a friend to write a "simple" app that I am unsure how to
proceed with. Any and all help is appreciated.

1) On start of the app, he wants a circle to appear in the middle of the
screen.
2) Clicking the circle allows the user to type 2-3 words in (on?) the
circle.
3) Double-clicking the circle draws a short line from the circle and creates
another circle, where step 2 is allowed.
4) The user can create this line of circles or, if desired, double-click a
previous circle, whereby another short line is created, in a different
direction, and another circle is connected.

A close analogy would be like a molecule diagram; some circles have up to 4
line drawing away, connected to other circles, some may not continue on...

I am unsure where to start. I am used to the standard forms, onclicks, etc,
but not ... graphically.

If you can provide pointers (no pun intended; this will eventually be
link-listed or database aware...) or links to example code or literature, it
would be appreciated.

Again, thanks.
Mark Smith
EMAIL REMOVED





   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Using graphics for thwe first time... help please.
Old
  (#2)
Larry Serflaten
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:54 AM

"ComputerSmith" <EMAIL REMOVED> wrote

> I was asked by a friend to write a "simple" app that I am unsure how to
> proceed with. Any and all help is appreciated.



This doesn't cover all the details, but it may get you started down the
path. It creates the nodes with numbered text (you'll have to get the
text from the user). I took a different tact with the mouse buttons,
use one to create a new item, and the other to move it.

To try it out, add an Image control to a new form and set its Index
property to 0.

Then add a cl*** to the project and paste in the code below in their
respective modules...

Have fun!
LFS

' [ Cl***1 ] ------------------------------------------------
Option Explicit

Public X As Long
Public Y As Long
Public Text As String
Public Handle As Image
Public Kids As New Collection


Friend Sub RenderLines(Surface As Variant)
Dim Item As Cl***1
'Connect lines first, then do circles/text
For Each Item In Kids
Surface.Line (X, Y)-(Item.X, Item.Y), vbBlack
Item.RenderLines Surface
Next
End Sub

Friend Sub RenderText(Surface As Variant)
Dim Item As Cl***1
' draw the circles and text
Surface.Circle (X, Y), 500, vbBlack
Surface.CurrentX = X - Surface.TextWidth(Text) \ 2
Surface.CurrentY = Y - Surface.TextHeight(Text) \ 2
Surface.Print Text;

For Each Item In Kids
Item.RenderText Surface
Next
Handle.Move X - 500, Y - 500, 1000, 1000
End Sub

Public Function Locate(ByVal Index As Long) As Cl***1
Dim kid As Cl***1
Dim test As Cl***1
' reutrns the cl*** whose handle has a certain Index
If Handle.Index = Index Then
Set Locate = Me
Else
For Each kid In Kids
Set test = kid.Locate(Index)
If Not test Is Nothing Then
Set Locate = test
Exit For
End If
Next
End If
End Function




' [ Form1 ] -------------------------------------------------------
Option Explicit
Private Node As Cl***1
Private Drawing As Boolean
Private StartX As Long, StartY As Long
Private OldX As Long, OldY As Long
Private StartNode As Cl***1


Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
DropIt Source, X, Y
End Sub

Private Sub Form_Load()
Me.FillStyle = vbFSSolid
Me.FillColor = vbWhite
Me.DrawWidth = 2
Set Node = NewItem(ScaleWidth \ 2, ScaleHeight \ 2, "Root", Image1(0))
End Sub

Private Sub Form_Paint()
Node.RenderLines Me
Node.RenderText Me
End Sub

Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Dim img As Image
Set img = Node.Locate(Index).Handle
DropIt Source, img.Left + X, img.Top + Y
End Sub

Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
'Select Draw Mode
Drawing = True
DrawMode = vbInvert
DrawStyle = vbDot
'Store start values
Set StartNode = Node.Locate(Index)
StartX = StartNode.X
StartY = StartNode.Y
OldX = X + StartNode.Handle.Left
OldY = Y + StartNode.Handle.Top
Else
OldX = X
OldY = Y
Node.Locate(Index).Handle.Drag vbBeginDrag
End If
End Sub

Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim XX As Long, YY As Long
If Drawing Then
' Convert Image click to Form coordinates
XX = X + StartNode.Handle.Left
YY = Y + StartNode.Handle.Top
'Erase old line
Line (StartX, StartY)-(OldX, OldY), vbBlack
'Draw new line
Line (StartX, StartY)-(XX, YY), vbBlack
OldX = XX
OldY = YY
End If
End Sub

Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Drawing Then
Drawing = False
DrawMode = vbCopyPen
DrawStyle = vbSolid
' Create a new Image control, make it visible
Load Image1(Image1.Count)
Image1(Image1.Count - 1).Visible = True
' Add a new item to the node
Node.Locate(Index).Kids.Add NewItem(X + StartNode.Handle.Left, _
Y + StartNode.Handle.Top, CStr(Image1.Count - 1), _
Image1(Image1.Count - 1))
Refresh
End If
End Sub

Private Function NewItem(ByVal X As Long, ByVal Y As Long, Text As String, Handle As Image) As Cl***1
Set NewItem = New Cl***1
With NewItem
.X = X
.Y = Y
.Text = Text
Set .Handle = Handle
End With
End Function

Private Sub DropIt(Source As Image, ByVal X As Long, ByVal Y As Long)
Dim This As Cl***1
' Drops item
Set This = Node.Locate(Source.Index)
This.X = X - (OldX - 500)
This.Y = Y - (OldY - 500)
Source.Drag vbEndDrag
Refresh
End Sub





-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#3)
Phil Godfrey
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:54 AM

Mark,

I know it doesn't help a lot....and I'm sure Larry's VB code does just what
you want however, there is an alternative and very simple in both creating
the graphics and the code...and that is to use Macromedia's FLASH! If you
have it or can get a copy you will find a simple solution just following the
integrated example(s)!

All the best,

Phil

"ComputerSmith" <EMAIL REMOVED> wrote in message
news:NocAb.5705$EMAIL REMOVED...
> Hi all.
> I have programmed VB6 apps before, ones that use dropdown listboxes, text
> boxes, etc... normal stuff.
>
> I was asked by a friend to write a "simple" app that I am unsure how to
> proceed with. Any and all help is appreciated.
>
> 1) On start of the app, he wants a circle to appear in the middle of the
> screen.
> 2) Clicking the circle allows the user to type 2-3 words in (on?) the
> circle.
> 3) Double-clicking the circle draws a short line from the circle and

creates
> another circle, where step 2 is allowed.
> 4) The user can create this line of circles or, if desired, double-click a
> previous circle, whereby another short line is created, in a different
> direction, and another circle is connected.
>
> A close analogy would be like a molecule diagram; some circles have up to

4
> line drawing away, connected to other circles, some may not continue on...
>
> I am unsure where to start. I am used to the standard forms, onclicks,

etc,
> but not ... graphically.
>
> If you can provide pointers (no pun intended; this will eventually be
> link-listed or database aware...) or links to example code or literature,

it
> would be appreciated.
>
> Again, thanks.
> Mark Smith
> EMAIL REMOVED
>
>
>
>
>



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#4)
Greg Siemon
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:54 AM

The following sub will make a round form

MakeMeRound Me

Private Declare Function CreateEllipticRgn Lib "gdi32" ( _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long _
) As Long

Private Declare Function SetWindowRgn Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hRgn As Long, _
ByVal bRedraw As Long _
) As Long

Sub MakeMeRound(TheControl As Object)
TheControl.Height = TheControl.Width
hRegion = CreateEllipticRgn(0, 0, TheControl.Width \ Screen.TwipsPerPixelX,
TheControl.Height \ Screen.TwipsPerPixelY)
lResult = SetWindowRgn(TheControl.hWnd, hRegion, True)
End Sub


"ComputerSmith" <EMAIL REMOVED> wrote in message
news:NocAb.5705$EMAIL REMOVED...
> Hi all.
> I have programmed VB6 apps before, ones that use dropdown listboxes, text
> boxes, etc... normal stuff.
>
> I was asked by a friend to write a "simple" app that I am unsure how to
> proceed with. Any and all help is appreciated.
>
> 1) On start of the app, he wants a circle to appear in the middle of the
> screen.
> 2) Clicking the circle allows the user to type 2-3 words in (on?) the
> circle.
> 3) Double-clicking the circle draws a short line from the circle and

creates
> another circle, where step 2 is allowed.
> 4) The user can create this line of circles or, if desired, double-click a
> previous circle, whereby another short line is created, in a different
> direction, and another circle is connected.
>
> A close analogy would be like a molecule diagram; some circles have up to

4
> line drawing away, connected to other circles, some may not continue on...
>
> I am unsure where to start. I am used to the standard forms, onclicks,

etc,
> but not ... graphically.
>
> If you can provide pointers (no pun intended; this will eventually be
> link-listed or database aware...) or links to example code or literature,

it
> would be appreciated.
>
> Again, thanks.
> Mark Smith
> EMAIL REMOVED
>
>
>
>
>



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#5)
ComputerSmith
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:55 AM

> This doesn't cover all the details, but it may get you started down the
> path. It creates the nodes with numbered text (you'll have to get the
> text from the user). I took a different tact with the mouse buttons,
> use one to create a new item, and the other to move it.
> ...
> Have fun!
> LFS


Larry,
Wow... I mean, WOW! I will try this out ASAP, but I wanted to say "thanks"
even sooner.

I appreciate the quick reply and am sure I will stumble more en route to
getting this done. I took a 2-year break from programming (network admin,
etc., position came up) and i have to say, at least for me, this isn't like
riding a bicycle - I've forgotten a lot!

Thanks again!
Mark Smith


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for the first time... help please.
Old
  (#6)
ComputerSmith
Guest
 
Posts: n/a
Default Re: Using graphics for the first time... help please. - 06-04-2007, 08:55 AM


"Phil Godfrey" <EMAIL REMOVED> wrote in message
news:bqstub$9oi$EMAIL REMOVED...
> I know it doesn't help a lot....and I'm sure Larry's VB code does just

what
> you want however, there is an alternative and very simple in both creating
> the graphics and the code...and that is to use Macromedia's FLASH! If you
> have it or can get a copy you will find a simple solution just following

the
> integrated example(s)!

Phil,
Thanks for the response; if Larry's suggestion doesn't give me enough...
confidence... to slog through, I'll definitely look at Flash (heck, I might
look at it anyways - may be the best way to go). Quick question: my friend
mentioned starting/stopping/starting up again with the app... sounds
definitely like data saving/database connection. Will Flash allow the
saving/retrieval of the data from a database?

Thanks,
Mark Smith


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#7)
ComputerSmith
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:55 AM

> MakeMeRound Me
>
> Private Declare Function CreateEllipticRgn Lib "gdi32" ( _
> ByVal X1 As Long, _
> ByVal Y1 As Long, _
> ByVal x2 As Long, _
> ByVal y2 As Long _
> ) As Long
>

etc...

Hi Greg,
You mentioned this will make a round form... I'm looking to be able to print
a form with the circles (with words in the circles - doesn't have to be
pretty, the 2-3 words can run through the circle) - not create a round
form...

I haven't tried any of the suggestions yet (hey, it's the weekend and I'm a
dad to 4 and 12 year old girls... too much to do, and not enough hours) but
I'm wondering whether I just misinterpreted the sentence, or if it is really
a round form... If the latter, sorry for not being clear enough.

Thanks again,
Mark Smith


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#8)
Roy Riddex
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:55 AM

"Greg Siemon" <EMAIL REMOVED> wrote in message
news:OXmAb.31115$Gj2.28160@okepread01...
> The following sub will make a round form
>
> MakeMeRound Me
>
> Private Declare Function CreateEllipticRgn Lib "gdi32" ( _
> ByVal X1 As Long, _
> ByVal Y1 As Long, _
> ByVal x2 As Long, _
> ByVal y2 As Long _
> ) As Long
>
> Private Declare Function SetWindowRgn Lib "user32" ( _
> ByVal hWnd As Long, _
> ByVal hRgn As Long, _
> ByVal bRedraw As Long _
> ) As Long
>
> Sub MakeMeRound(TheControl As Object)
> TheControl.Height = TheControl.Width
> hRegion = CreateEllipticRgn(0, 0, TheControl.Width \

Screen.TwipsPerPixelX,
> TheControl.Height \ Screen.TwipsPerPixelY)
> lResult = SetWindowRgn(TheControl.hWnd, hRegion, True)
> End Sub
>


I tried copying and pasting but the round form doesn't work, I got a regular
rectangle form.


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Using graphics for thwe first time... help please.
Old
  (#9)
Mike Williams
Guest
 
Posts: n/a
Default Re: Using graphics for thwe first time... help please. - 06-04-2007, 08:55 AM

"Roy Riddex" <EMAIL REMOVED> wrote in message
news:WIQAb.11627$EMAIL REMOVED...

> I tried copying and pasting but the round form doesn't work,
> I got a regular rectangle form.


Greg's code works okay here, Roy. Are you sure that you pasted it in
correctly. For example, have you included the line "MakeMeRound Me" in a
event of some sort (such as a button click)? There are a couple of problems
with undeclared variables, but otherwise it works okay. Paste the following
into a Form containing a command button (Command1) and then run the project
and click the button.

Mike

Option Explicit
Private Declare Function CreateEllipticRgn Lib "gdi32" ( _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long _
) As Long
Private Declare Function SetWindowRgn Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hRgn As Long, _
ByVal bRedraw As Long _
) As Long

Sub MakeMeRound(TheControl As Object)
Dim hRegion As Long, lResult As Long
TheControl.Height = TheControl.Width
hRegion = CreateEllipticRgn(0, 0, TheControl.Width \ _
Screen.TwipsPerPixelX, TheControl.Height \ _
Screen.TwipsPerPixelY)
lResult = SetWindowRgn(TheControl.hWnd, hRegion, True)
End Sub

Private Sub Command1_Click()
MakeMeRound Me
End Sub

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top