Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Interface and Graphics

Post new topic   Reply to topic
Static Controls... Goto page 1, 2  Next
View previous topic :: View next topic  
Author Message
Tsudeki
Newbie


Joined: 09 Apr 2004
Posts: 10

PostPosted: Apr 10th, 2004 09:04 PM    Post subject: Static Controls... Reply with quote

Okay maybe they aren't static..but they certainly stay in the same spot(though they do move per se...anyway)...here's what I'm having problems with..

I want to keep a control in the upper right hand corner of my program and I want it to stay there when the form is resized. I've thought of using a picture box and aligning it to the right but that may cause problems with what I need it for though I'm not going to rule out the picture box, so..any suggestions are welcome ^^;

Thanks in advance..
Back to top
View user's profile Send private message
Gilad_r
Centurion


Joined: 03 Mar 2004
Posts: 156

PostPosted: Apr 11th, 2004 02:52 AM    Post subject: Reply with quote

you got 3 options that will work without the control jumping (afaik)
- use the picbox and place the control there. what problems would accur by using it? maybe we can overcome them...
- capture the WM_PAINT message sent to the parent window, and then draw the window yourself...
- create the control with the CCS_RIGHT style (this will also cause the control to be stretched to the height of the window though...)

hope this will help you
Gilad
_________________
"you should make amends with you" (Incubus)
Back to top
View user's profile Send private message
Tsudeki
Newbie


Joined: 09 Apr 2004
Posts: 10

PostPosted: Apr 11th, 2004 03:52 PM    Post subject: Reply with quote

Okay let's say I use the picture box, here's the problem:

There really isn't any..with the picture box that is, I suppose I'll use it Smile

The other problem would be the text box. I have it to resize with the window, however, my resizing function seems to work less than perfectly. For instance, if the text box is 1000 twips from all sides of the form, when the form is maximized, it becomes more around 2500 twips or more from the sides of the form. How can I keep it at 1000 twips from the edge(on all sides) when resizing?
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 04:10 PM    Post subject: Reply with quote

Can you post the code you have so far (For resizing the textbox) ?

To keep a button in the top left corner, can't you do this? Why do you need a pic box :

[vb:1:11331e39bc]Private Sub Form_Resize()
Command1.Move Me.ScaleWidth - Command1.Width, 0
End Sub[/vb:1:11331e39bc]
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Gilad_r
Centurion


Joined: 03 Mar 2004
Posts: 156

PostPosted: Apr 11th, 2004 04:13 PM    Post subject: Reply with quote

*EDIT*

P.T.A.M. wrote:
To keep a button in the top left corner, can't you do this? Why do you need a pic box :

[vb:1:6ec1c45f50]Private Sub Form_Resize()
Command1.Move Me.ScaleWidth - Command1.Width, 0
End Sub[/vb:1:6ec1c45f50]


hmm... this is weird:
i tried aligning some form to be at the right bottom corner of it's owner form by using the move method or the form's position properties but i kept getting these jumps or skips and sometimes it wouldn't even align right. but for some reason now it works perfectly... isn't that strange? the code was exactly as it is now.
(it was about a week ago)


*EDIT2*
correction - it wasn't exactly as before, i put it in the paint event.
now i remembered that i did that because there is no move event...
also tried subclassing and watching for the WM_MOVING message but i still got skipping results
any ideas?


Last edited by Gilad_r on Apr 11th, 2004 04:41 PM; edited 1 time in total
Back to top
View user's profile Send private message
Tsudeki
Newbie


Joined: 09 Apr 2004
Posts: 10

PostPosted: Apr 11th, 2004 04:28 PM    Post subject: Reply with quote

I wanted to keep that control in the upper right of the form, not upper left, since upper left woulda been simple since it stays there anyway @_@...

This resize code isn't my own, since I've never really comprehended the resizing stuff, I got this from planet-source-code.com and it works well as long as your control actually touches the border of the form, however I don't want it to touch the border anymore...

[vb:1:c204fb48a0]Public Sub ResizeControl(inControl As Control, pfrmIn As Form)
On Error Resume Next
Dim i As Long
Dim widthfactor As Single, heightfactor As Single
Dim minFactor As Single
Dim yRatio, xRatio, lTop, lLeft, lWidth, lHeight As Long

yRatio = PerHeight(pfrmIn)
xRatio = PerWidth(pfrmIn)
i = FindControl(inControl, pfrmIn.Name)

If inControl.Left < 0 Then
lLeft = CLng(((ControlRecord(i).Left * xRatio) \ 100) - 75000)
Else
lLeft = CLng((ControlRecord(i).Left * xRatio) \ 100)
End If

lTop = CLng((ControlRecord(i).Top * yRatio) \ 100)
lWidth = CLng((ControlRecord(i).Width * xRatio) \ 100)
lHeight = CLng((ControlRecord(i).Height * yRatio) \ 100)

If TypeOf inControl Is Line Then
If inControl.X1 < 0 Then
inControl.X1 = CLng(((ControlRecord(i).Left * xRatio) \ 100) - 75000)
Else
inControl.X1 = CLng((ControlRecord(i).Left * xRatio) \ 100)
End If

inControl.Y1 = CLng((ControlRecord(i).Top * yRatio) \ 100)
If inControl.X2 < 0 Then
inControl.X2 = CLng(((ControlRecord(i).Width * xRatio) \ 100) - 75000)
Else
inControl.X2 = CLng((ControlRecord(i).Width * xRatio) \ 100)
End If

inControl.Y2 = CLng((ControlRecord(i).Height * yRatio) \ 100)
Else
inControl.Move lLeft, lTop, lWidth, lHeight
inControl.Move lLeft, lTop, lWidth
inControl.Move lLeft, lTop
End If
End Sub[/vb:1:c204fb48a0]
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 04:51 PM    Post subject: Reply with quote

Quote:
I wanted to keep that control in the upper right of the form, not upper left, since upper left woulda been simple since it stays there anyway @_@...


My code does that, right?

You also seem to be missing some functions in the code you posted... The PerHeight?
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 05:01 PM    Post subject: Reply with quote

How about something simple like this?

[vb:1:37753fedb8]Private Sub Form_Resize()
Text1.Move 1000, 1000, Me.ScaleWidth - 2000, Me.ScaleHeight - 2000
End Sub[/vb:1:37753fedb8]
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Tsudeki
Newbie


Joined: 09 Apr 2004
Posts: 10

PostPosted: Apr 11th, 2004 05:01 PM    Post subject: Reply with quote

[vb:1:1378e73826]Private Function PerWidth(pfrmIn As Form) As Long
Dim i As Long

i = FindForm(pfrmIn)
If i < 0 Then i = AddForm(pfrmIn)

PerWidth = (pfrmIn.ScaleWidth * 100) \ FormRecord(i).ScaleWidth
End Function

Private Function PerHeight(pfrmIn As Form) As Single
Dim i As Long

i = FindForm(pfrmIn)
If i < 0 Then i = AddForm(pfrmIn)

PerHeight = (pfrmIn.ScaleHeight * 100) \ FormRecord(i).ScaleHeight
End Function

Private Function FindControl(inControl As Control, inName As String) As Long
Dim i As Long

FindControl = -1
For i = 0 To (MaxControl - 1)
If ControlRecord(i).Parrent = inName Then
If ControlRecord(i).Name = inControl.Name Then
On Error Resume Next

If ControlRecord(i).Index = inControl.Index Then
FindControl = i
Exit Function
End If
On Error GoTo 0

End If
End If
Next i
End Function[/vb:1:1378e73826]

Sorry about that, here's the other stuff that code uses.

And yes, your code does do that apparently lol, in your post you put that it "makes it stay in the top left"...so I got confused @_@ sorry..
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 05:03 PM    Post subject: Reply with quote

Oh, my mistake... Typing mistake that is Biggrin How about the textbox resizing code?
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Tsudeki
Newbie


Joined: 09 Apr 2004
Posts: 10

PostPosted: Apr 11th, 2004 05:09 PM    Post subject: Reply with quote

You know what...forget it. <_< I solved my problem by doing this:

[vb:1:1a0bf32ba3]Private Sub Form_Resize()

lblClose.Move Me.ScaleWidth - Label9.Width, 0
txtOne.Width = Me.ScaleWidth - 200
txtOne.Height = Me.ScaleHeight - 200

End Sub[/vb:1:1a0bf32ba3]

<_<;; ^_^; Turned out to be a pretty easy thing lmao...~_~;;;;; sorry for all the fuss @_@...Biggrin
Back to top
View user's profile Send private message
Gilad_r
Centurion


Joined: 03 Mar 2004
Posts: 156

PostPosted: Apr 11th, 2004 05:15 PM    Post subject: Reply with quote

any ideas on my issue? Cry
_________________
"you should make amends with you" (Incubus)
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 05:28 PM    Post subject: Reply with quote

Well I think all the Move event does is set the left/top/width/height properties... You can do it seperatelly also... Have you tried it?
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Gilad_r
Centurion


Joined: 03 Mar 2004
Posts: 156

PostPosted: Apr 11th, 2004 06:11 PM    Post subject: Reply with quote

you mean the move method? yes i did try it, it's where i put the code that makes the difference: on WM_MOVE works better than on WM_MOVING but still not as perfect as on WM_SIZE or WM_SIZING...
i also tried on WM_PAINT but that's the worst of it all.
_________________
"you should make amends with you" (Incubus)
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Apr 11th, 2004 06:36 PM    Post subject: Reply with quote

I am getting confused (once again)... Why must you subclass? Could you explain the problem again? I'm obviously missing something :ermm:
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Interface and Graphics All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic