How to use scrollbar in visual basic 6? - vb6

My Windows Application in VB 6 is having a form that contains hell lot of controls. And if the screen size at client's environment is smaller, most of the controls do not appear.
What I want to do is to provide users a vertical and horizontal scrollbar so that user can scroll across all controls.
Anyone having any idea of how to implement this?
P.S. Please do not provide examples showing just labels to display scroll value :)

I like David's answer, but if you want to do this with the scrollbars, first, you need to put all of your controls into a frame that fits them. You want to move 1 control not a "hell of a lot of controls". Second put your scroll bars into the form and in the Form_Resize event add some code to resize the scroll bars with the form. After resizing the scrollbar you need to do some math to set the Max, SmallChange, and LargeChange properties. I am showing the Min property just so you know it never changes, just set it in the designer. This example uses only a horizontal scrollbar because I am too lazy to include a vertical scrollbar too. Finally, add code to the scrollbar Change event to move the frame around.
Private Sub Form_Resize()
HScroll1.Move 0, Me.ScaleHeight - HScroll1.Height, Me.ScaleWidth
HScroll1.Min = 0
HScroll1.Max = Frame1.Width - Me.ScaleWidth
HScroll1.SmallChange = HScroll1.Max / 100
HScroll1.LargeChange = HScroll1.Max / 10
End Sub
Private Sub HScroll1_Change()
Frame1.Left = -HScroll1.Value
DoEvents ' this is not strictly necessary, but smooths the scolling some
End Sub
You also need error handling code. I am a lazy example coder.

One way is to turn on the scroll bars of your form using Windows API calls. This is different from using ScrollBar controls; turning on the form's own scroll bars keeps the scroll bars from interfering with the tab order, for example.
Here is a good page explaining how to do this, along with a helper class:
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/Adding_Scroll_Bars_To_Forms__PictureBoxes_and_UserControls/article.asp

Related

How do you update all the TreeView items full area when the vertical scrollbar shows up or goes away?

I am using NM_CUSTOMDRAW to draw tree view items. My items right justify parts of it by using a right margin based on the RECT area reported available. The issue I have is that when the vertical scrollbar appears or disappears, only the item expanded/collapsed and the area under the scrollbar seems to update (invalidated regions). This causes the repaint requests (with the new width) to not update the area correctly.
For example (using text and a single space as example): You could have something with the scrollbar be right justified text ## where ## is the scrollbar then when the scrollbar goes away you end up with right justified text t instead of right justified text
Is there a good way to fix this?
One thought is if I could catch a message when a scrollbar shows up or goes away, I could just invalidate the window to force a redraw. Is there such a message?
Or is there a way to add to the invalidated region without triggering a redraw loop but would update the full items area?
Another thought is I can just use the full window RECT size and use a right margin large enough that wouldn't be under the scroll area but I'd rather not do that.
Thanks!

Erasing border of a TabControl in vbnet without making a CustomTabControl

I want to draw my own TabControl with a different style. I have a TabControl in my form for which i have appended the event handler,
MainTabControl.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler MainTabControl.DrawItem, AddressOf TabControlPaint
TabControlPaint() is a method where i paint my own graphics using Bitmaps amd Buffer variables. (see here)
I'm not inheriting from TabControl because my Application has many forms and windows and that would force me to go to each form and change the TabControl for my CustomTabControl. I would like to be able to draw my own tabs overwriting the DrawItem event.
I came up with this result Screenshot, where you can see the red border, a different background color for the tabs, even different color schemes for a tab went selected.
What i can't figure out is to erase that white 3D border that appears only on the selected tab. I'm guessing is drawn on top when the OnPaint() method is called after the drawItem event (correct me if i'm wrong). If i debug, that white 3D border appears after the method TabControlPaint (the one i'm calling for the DrawItem event) has finished execution.
To make the question more clear, i want to design my own TabControl without overwriting the OnPaint method. What i have come up so far was not succesfull just because of that windows drawn border. Is there a way to take it off? Or do you know any alternatives?
I managed to solve the problem by,
For Each page As TabPage In MainTabControl.TabPages
AddHandler page.Paint, AddressOf test
Next
then in my test function i draw whatever i want. In this case i just drew a rectangle. It is not efficient but i think it can be improved by double buffering.
Private Sub test(ByVal sender As System.Object, ByVal e As PaintEventArgs)
Dim ScreenGraphic As Graphics = Graphics.FromHwnd(MainTabControl.Handle)
Dim myRect As Rectangle = MainTabControl.GetTabRect(MainTabControl.SelectedIndex)
Dim borderColor As Pen = New Pen(Color.FromArgb(42, 38, 37), 5)
myRect.X -= 1
myRect.Y -= 1
ScreenGraphic.DrawRectangle(borderColor, myRect)
End Sub

Receive touch events after settings StackLayout.TranslateX property

I have a ContentView with a StackLayout with multiple children sized to the full width of the screen. In other words, if the screen width is 320 and I have five children, the inner StackLayout is resized to 1600.
In this ContentView, I have Next and Previous buttons that when clicked, animate the inner StackLayout's TranslateX property. Basically, I'm creating a carousel by translating the StackLayout within the ContentView. I chose this route because I was having layout issues using a ScrollView and a custom renderer when I would modify that layout of the view (by hiding labels, etc.)
However, I've hit a snag. Content that appears after I set the TranslateX property doesn't receive any tap events. I believe I might have to reset some tappable area, but I'm not even sure where to begin with that. Does anyone have any suggestions?
I posted this same question in Xamarin's Forums, and someone there answered. For anyone looking, the answer is here: https://forums.xamarin.com/discussion/comment/142914/#Comment_142914
If that link stops working at some point in the future for some reason, the relevant answer is:
Hit testing is done based on the actual frame of the control determined by layout, but translation happens after layout. Therefore hit testing does not take translation into account. If you want a view to be touchable then you should update its layout directly rather than using translation.

Treeview control in Win32 API - how to display a single treeview item using different fonts?

I'm faced with a problem where I need to display some characters in a tree-view item (those belonging to the Symbol charset) using Symbol font while others in the default System font (Segoi UI on my Windows 7).
Custom draw allows us to draw different items using different fonts, but I would like to draw the same item string using different fonts as it applies to each character in the string as told above.
So, what I've done with not-so-pleasing results w.r.t. drawing performance upon a horizontal scroll when the number of items is more so far is this:
I disabled horizontal scrolling in my tree-view control using TVS_NOHSCROLL style (since I'm using my own scroll bar control inside the tree-view window to handle all horizontal scrolling)
I sub-classed the treeview control and in the sub-classed winproc, I handle the horizontal scroll notification and mouse notification (where I do my own hittesting and send message like TVM_EXPAND and TVM_SELECT as a result of mosue clicks/double-clicks). Also the scroll bar range is set based on how wide my custom drawn string is (the maximum length amongst all items).
I draw the string for each item upon receiving CDDS_ITEMPOSTPAINT using my own fonts for each character in the item.
The above approach (I left out some details for the sake of brevity) works BUT there are some problems which makes me post this question here and look for an alternare way:
Problems:
The horizontal scroll bar control I create is hosted "inside" the tree-view control at the bottom of the tree-view window. However, when the number of items goes beyond what the tree-view client area can accommodate vertically, the last visible tree-view item gets obscured by the scroll bar control. This can be solved by not making the scroll bar a child of the tree-view and hosting it outside the tree-view window just below it. But I don't want to do this since the scroll bar should typically be a child window of the tree-view.
This is the major one. Since I draw the items myself at each horizontal scroll, the drawing performance upon horizontal scrolling is very slow and also leads to flicker upon scrolling.
Any ideas will be much appreciated as I've been grappling with this for the last one week without success.
I can also post the relevant code here if you want to see the approach I took but I'm sure there shoould be a better approach to this and there must be some other people who would've faced this problem and solved it in the past.
Thanks in advance.
Custom-draw allows you to draw items however you want. You are not limited to a single font per item. When you receive the NM_CUSTOMDRAW notification, draw whatever you want on the provided HDC for the specified item. You can draw pieces of text in one font, pieces of text in a different font, etc. Be sure to return CDRF_SKIPDEFAULT so the TreeView itself will not try to draw anything on the item.
#Anurag S Sharma: I tried to edit this into Remy's answer. It's incomplete as is, but addresses your comment/concerns and answers this particularly vexing/useful question...
The problem is that ff I return CDRF_SKIPDEFAULT, Windows does not even draw the +/- buttons (expanding/collapsing) nor the indent lines in the control which I do want Windows to draw. – Anurag S Sharma
To retain the lines, buttons, and icons you can use ExcludeClipRect to mask only the text region and instead of returning CDRF_SKIPDEFAULT, return 0 as if you didn't draw anything. This itself would not be necessary if the text of the tree item was empty, except that the margins of the text will always be drawn by the default handler (note that Microsoft's controls do not always respect clipping shapes, but in this case they do.)
To replicate the classic TreeView label style in your custom draw procedure you need to do something like the following:
HTREEITEM item = (HTREEITEM)p->dwItemSpec;
TreeView_GetItemRect(p->hdr.hwndFrom,item,&p->rc,1);
RECT cr, rc = p->rc; GetClientRect(p->hdr.hwndFrom,&cr);
DrawTextW(p->hdc,text,-1,&rc,DT_CALCRECT|DT_NOPREFIX|DT_NOCLIP);
rc.right+=4; rc.bottom+=2; IntersectRect(&rc,&cr,&rc);
ExtTextOutW(p->hdc,rc.left+2,rc.top+1,ETO_CLIPPED|ETO_OPAQUE,&rc,text,wcslen(text),0);

hbox scrollbar is not showing

i need to put a horizontal scrollbar in a dynamically created Hbox. im writting the code like this:
hbxWallAImg = new HBox();
hbxWallAImg.horizontalScrollPolicy="on";
but still the no scrollbar is comming.
i have tried by setStyle also. but it is also not working.
The scroll bar will not be visible unless the content of the box doesn't fit in the box's view port. So just by setting the scroll policy, it won't be displayed, but rather when the element will "know" that in case its content doesn't fit, it should display scroll bars. You also need to add some children and dimensions (with, height) to the HBox.
Without dimensions, it will "stretch" as much as it needs to accommodate the content, so no scroll bars will be visible in this case also.
You can find all the info about view ports and scrolling in Flex 4 here: http://www.adobe.com/devnet/flex/articles/flex4_viewport_scrolling.html
Hope this helps.
Have a good day,
Romi

Resources