 |
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: how to make label sizes dynamic within a frame
despite using autosize property of a label? Have you tried this?
Label1.AutoSize = False
Label1.Width=SomeWidth
Label1.Caption = "Some text that will appear as multiline text"
Label1.AutoSize = True |
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
17-04-2005 at 10:23 PM |
|
|
maheeru Level: Sage
 Registered: 13-04-2005 Posts: 60
|
Re: how to make label sizes dynamic within a frame
It doesn't work for me. My problems are compounded with the combination of 2 factors.
Labels awkwardly get arranged within the frame during runtime. Complete content of a particular field though comes in a label caption, many last characters in a line, gets hidden. I could not scroll the frame to view those characters. This becomes an impasse.
I have given the code I ve used for one label to be displayed, and associated function with the code(Likewise I ve 6 labels for answer choices). I have already given the code in previous attachment which I ve tried for scrolling the frame.
I will appreciate any quick help on this topic. Thanx.
Refer my code:
This code I use for displaying a fields content from a table as label's caption:
OptionA.Left = LblChoice1.Left - 500
OptionA.Top = LblChoice1.Top
Check1.Left = LblChoice1.Left - 500
Check1.Top = LblChoice1.Top
LblChoice1.AutoSize = False
LblChoice1.Width = 2000
lines = glo.rs.Fields("ChoiceA")
lines = Removenewlinechar(lines)
lines1() = Split(lines, , 1)
LblChoice1.Caption = ""
For i = 0 To UBound(lines1)
If (i <> 0 And i Mod 12 = 0) Then
LblChoice1.Caption = LblChoice1.Caption & vbCrLf & lines1(i)
Else
LblChoice1.Caption = LblChoice1.Caption & " " & lines1(i)
End If
Next
LblChoice1.Refresh
LblChoice1.AutoSize = True
---------------------------------------------------------------------
Public Function Removenewlinechar(str As String) As String
str = Trim(str)
Dim L As Integer, i As Integer
Dim S As String
Dim Prev_char As String * 1
S = ""
L = Len(str)
i = 1
Do
Prev_char = Mid(str, i, 1)
i = i + 1
S = S + Prev_char
If Prev_char = vbCrLf Then
Do While (i < L) And (Mid(str, i, 1) = vbCrLf)
i = i + 1
Loop
End If
Loop Until i > L
str = S
Removenewlinechar = S
End Function
----------------------------------------------------------------------
This is the code I attached in my previous post for scrolling the frame.
Private Sub picCanvas_Resize()
HScroll1.Min = 0
VScroll1.Min = 0
HScroll1.Max = Frameans.Width
VScroll1.Max = Frameans.Height
'Resize the scroll bars along the frame.
HScroll1.Move Frameans.Left, Frameans.Height - SB_HEIGHT, Frameans.Width - SB_WIDTH
VScroll1.Move Frameans.Width - SB_WIDTH, Frameans.Height, SB_WIDTH, _
Frameans.Height - SB_HEIGHT
cmdFiller.Move Frameans.Width - SB_WIDTH, Frameans.Height - SB_HEIGHT, _
SB_WIDTH, SB_HEIGHT
' Put these controls on top.
HScroll1.ZOrder
VScroll1.ZOrder
cmdFiller.ZOrder
picCanvas.BorderStyle = 0
' A click on the arrow moves one pixel.
HScroll1.SmallChange = ScaleX(25, vbPixels, vbTwips)
VScroll1.SmallChange = ScaleY(25, vbPixels, vbTwips)
' A click on the scroll bar moves 16 pixels.
HScroll1.LargeChange = HScroll1.SmallChange * 50
VScroll1.LargeChange = VScroll1.SmallChange * 50
' If the frame is larger than the picCanvas picture box,
' we don't need to show the corresponding scroll bar.
If Frameans.Width < picCanvas.Width + SB_WIDTH Then
HScroll1.Visible = True
HScroll1.Max = picCanvas.Width + SB_WIDTH - Frameans.Width
Else
HScroll1.Value = 0
HScroll1.Visible = False
End If
If Frameans.Height < picCanvas.Height + SB_HEIGHT Then
VScroll1.Visible = True
VScroll1.Max = picCanvas.Height + SB_HEIGHT - Frameans.Height
Else
VScroll1.Value = 0
VScroll1.Visible = False
End If
' Make the filler control visible only if necessary.
cmdFiller.Visible = (HScroll1.Visible Or VScroll1.Visible)
MoveCanvas
End Sub
Sub MoveCanvas()
picCanvas.Move -HScroll1.Value, -VScroll1.Value
End Sub
In every scroll change I ve called movecanvas. But problem is picturebox resize event is not raised even I scroll the scroll bars and the code does not serve its purpose. Please help me in this trouble.
P.S: Thanx Steve and I will try your code . But here, there is 3rd dimension too. The function removenewlinechar function which I wrote to discard accidental newline characters from database is not working. I am looking forward towards all genius's help in solving my problems.
[Edited by maheeru on 20-04-2005 at 06:55 AM GMT]
[Edited by maheeru on 20-04-2005 at 07:09 AM GMT]
[Edited by maheeru on 22-04-2005 at 11:44 AM GMT]
[Edited by maheeru on 22-04-2005 at 11:51 AM GMT]
|
|
20-04-2005 at 06:37 AM |
|
|
maheeru Level: Sage
 Registered: 13-04-2005 Posts: 60
|
Re: how to make label sizes dynamic within a frame
1)My function named removenewlinechar() does not remove endline characters in a specific fields's content.
What's the logical error? Can anybody suggest any improvement in this function.
2) Steve, I have tried your given piece of coding. It gives following run time error 28: saying "out of stack space" .
Please help me to scroll the label contents within the frame.
|
|
24-04-2005 at 07:21 AM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: how to make label sizes dynamic within a frame
1) shorter version
Public Function Removenewlinechar(str As String) As String
Removenewlinechar=replace(trim(str),vbcrlf,"")
end sub |
2) you are having a recursive loop with no exit. Try this:
Sub MoveCanvas()
picCanvas.Move -HScroll1.Value, -VScroll1.Value
End Sub |
This code has an assumption that values for left and top property of label control that you want to scroll are equal to 0. If not, you should use this code:
Sub MoveCanvas()
picCanvas.Move LeftValue-HScroll1.Value, TopValue-VScroll1.Value
End Sub |
where LeftValue and TopValue are left and top coordinates of label control.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
24-04-2005 at 05:29 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: how to make label sizes dynamic within a frame
I am not following you... You cant scroll context of label within label. I dont see the reason why are you having these "hidden characters" in label. THe code you have is ment to give effect of scrolling the text in label. basically what it does is (when scrolling to the right), moves the whole label to the left, therefore revealing the right part of the label that couldnt fit in the frame window - or to put it simpler, left part of the label control becomes invisible, while right part of the label becomes visible.. If you have more controls on this frame, then you should put labels that you want to scroll in separate frame(s), so they wont overlap with other controls.
As for the resize event, you need to determine first when this event should be raised (after what sircumstances), to avoid unecessary execution of the code. For example if picture need to be resized when the form is resized, then call it from Form_resize event...
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
29-04-2005 at 02:08 AM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: how to make label sizes dynamic within a frame
quote: P.s: Moving labels is not what Im looking. To be simple, I want a way to read those hidden chunk of characters just like scrolling a web page or a vb form during runtime. Since one cant scroll the contents within a label I included a picturebox control within the frame called PicCanvas and over it I placed the labels. But scrolling picCanvas also doesnot give the desired result. Help me out of this trouble.
As I see it, it is not a matter of container, but label control. If characters are hidden within the label, and not by container, then no scrolling will help you. So what you should do is:
quote: Goran, I too dont understand why a chunk of characters become hidden while displaying those answer choice. I guess its more to do with dimensions of labels and the frame control.
see what is wrong with your label. I would do this:
Caclulate how much can label have width within the frame, and to be shown completely (not counting on its height, just width). After that you should have (if not already) label's WordWrap property set to true. And then you should put the code I gave you in the event where you are loading data in label.
Label1.AutoSize = False
Label1.Width=CalculatedWidth ' the one you calculated above
Label1.Caption = "The text you are loading in label"
Label1.AutoSize = True |
When putting things like this, you wont be needing horisontal scrollbar, since the label width is set to visible area of the container control. After this, you should only be concerned with the label height. Since most probably height will be much bigger than the container can handle, you need to program vertical scrollbar and scrolling TopToBottom and vice-versa.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
01-05-2005 at 06:24 PM |
|
|
maheeru Level: Sage
 Registered: 13-04-2005 Posts: 60
|
Re: how to make label sizes dynamic within a frame
Goran, I ve tried various combinations of width for a label using trial and error, and I ve chosen value for a label say label.width =5200(picturebox's=6000 and frame's=6375). I dont know whether it will stand good for any length of "label content" but atleast it works for all the strings what I have with me currently. If I tried greater length for labels(>5200) contents become hidden.
Interestingly, it seems that label did not hid the content rather it was due to the static dimensions of picturebox picCanvas.
When I tried with greater widths for picturebox (picCanvas), though vertical scrollbar disappeared(picturebox overshadowed it) , when I scrolled horizontal scrollbar, I could view all the content of the label. I could not understand the reason behind this. (I guess that if picturebox's height and width increased with the dimensions of label it would ve been easy to scroll the picturebox)
picture_resize event could not be raised unless picturebox's width or height is explicitly increased through a variable.
When label's dimensions change inside frame, there's no frame resize event equivalent to form-resize event that could be raised and form_resize event could not be raised while displaying labels, within the frame on picturebox.
To scroll the contents vertically using vertical scroll bar is also have become difficult. The lower label's contents get hidden because of picture box's dimension it seems. The same sordid story continues. How to scroll the picturebox vertically so that contents in the lower label will also become completely visible.
I need a solution to scroll labels contents vertically without any problem.
P.s: 1) If only, contents exceed the visible window of piccanvas on frame, should I get vertical scrollbar visible. How to do it?
2) I ve attached different bmp files for differentiation 1)contents are not scrolled vertically while I ve not given piccanvas's height greater than frame.2) contents could be scrolled only by making picturebox's height =say 8000 which is greater by 2 folds than frame's height.
than frame's height 4815.
[Edited by maheeru on 06-05-2005 at 12:47 PM GMT]
____________________________ Attached:
frame.zip 25 KB (Downloads: 3)
|
|
04-05-2005 at 07:06 AM |
|
|
maheeru Level: Sage
 Registered: 13-04-2005 Posts: 60
|
Re: how to make label sizes dynamic within a frame
Goran, I ve tried a lot of combinations for scrolling the picturebox vertically so that labels hidden by invisible part of picture box will become visible. But except changing picturebox's height nothing have worked. Its also not right solution.
Is there any way out to solve this problem.
|
|
09-05-2005 at 06:44 AM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: how to make label sizes dynamic within a frame
Since you are having some much trouble with label control, have you tried with textbox control instead? With multiline property set to True, locked to true, backcolor to form's backcolor and scrollbar set to vertical, will make you rlife much easier.... No frames (or pictureboxes, since you were determined to use this type of container), no extra scrollbars, no extra code..
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
10-05-2005 at 11:10 AM |
|
|
|
|
 |
 |