Draw border around controls on VBA Userform without using a Frame? - vba

I am designing a VBA UserForm (in Excel, if it is relevant) and I would like some controls to be visually grouped together.. but when I put them in a frame, I am getting some undesired results (part of it has to do with the RefEdit control which seems to be particularly unhappy inside a frame).
Is there a way to draw a border around a group of controls on a form without putting them inside a Frame?

Use a label with the caption deleted and the border style set to fmBorderStyleSingle. It may appear on top of your other controls, so right click on it and select "send backwards" until it's behind your other controls.

The best way to do this would be to create the shape over where you need it to be. Drag highlight everything that you want on top of it, then right click and brink it all forwards. Then when you drag your shape back over the top it will in fact be underneath everthing else.
Hope that helps.

This worked for me and I was at first having the same issue where I had to choose to "Send Backward" up to 30 times per label in some cases. I found that hitting the Ctrl-K sends it to the back of all controls with one time hitting these keys.

Related

VB Form Not Holding Format

In the design window, I have my controls formatted one way, but when I run my program, the formatting changes. The window looks larger and the digit button is no longer aligned. I have no clue how to fix this. I am taking an intro level course, so I can't fix this with code. When I wrote my first couple of programs, I didn't have an issue with resizing, but for the last two or three, they never hold their size.
My Program
the above issue please check the anchor tag of each control it should be Top left.
To hold the control position
1 Add panel control to form then dock it to form
2 Add the other
control it will hold the control position as well

Using the Form Scrollbar to Control Image Transparency in Excel VBA

I'm struggling in making a form scrollbar to control the image transparency. To be specific, I've got two images that I'm linking to two buttons. Hide/show buttons, and I want the scrollbar to control the image transparency as shown in the image below. Your help would be appreciated. I can't wrap my head around to code it.
Here is a low-tech approach.
1) Create a rectangle and fill it with your picture. This doesn't require any VBA.
2) Insert the scrollbar and, using the properties, link your scrollbar to a cell with the default 0-100 range of the scrollbar's values. For example, in the following picture I linked it to J20:
Then, in a standard code module put:
Sub SetTransparency()
Sheets(1).Shapes("Rectangle 1").Fill.Transparency = Sheets(1).Range("J20") / 100
End Sub
(With of course things like Sheets(1), "Rectangle 1" and "J20" to be adjusted to match your situation)
Then - all you have to do is right click on the control and select Assign Macro to assign this macro to your control. It can be used like:
Possibly unfortunately (depending on your desires) the transparency doesn't change continuously as you scroll. AKAIK, you would need to use Active-X controls for that.

What technique will I use if i want to change this panel when I click a button in VB

I just have it in my mind. And I can't explain it so here it goes.
A system that only uses 1 form?
It have a two panel, left and right.
The left is consist of buttons
Then the right is associated on the buttons and will change whether what button will be clicked.
Any ideas?
My preference is to do this via custom controls, rather than panels... but panels can work too.
There are a number of ways to do this:
Keep all of the controls layered on top of each other, and then set the Visible property to false for controls/panels you don't care about and to true for the Control/Panel that you do
Move the controls you don't care about out of the visible area
Remove/Add the Controls/Panels from Form's controls collection entirely
I think you can also get a TabControl to put the tabs along the left side, with some formatting that looks more like buttons, such that what you want will be handled without needing to write any code to switch layouts
Any of those can work. Whichever option you use, I have two recommendation for controlling layout and making the transitions smooth.
Call SuspendLayout() before making any changes, and then call ResumeLayout() when you're done. This will help avoid stuttering or a partially rendered form.
Look at the TableLayoutPanel Control. This control will allow you to arrange your top-level panels so that they can be resized with proportion. If you also then dock your individual panels, you can quickly build your program so that it resizes correctly.
You can have several panels, one on top of another. Change their visibility, depending on which one you need at a given moment.
Option #2 would be using a vertical tab control (or a tab strip - see another answer there).

How to implement wizard control in VB.NET

In VB6 I have been using pictureboxes as containers a lot.
For example I put 5 pictureboxes onto a form, and as soon as the user clicked the "Next" button, I brought the next picturebox into the foreground.
This has been extremely convenient.
Now I am fighting with doing something similar in VB.NET.
My attempts were not really successful. A picturebox does not really hold my controls, they seem to jump out now and then, and I can not really make out on which picturebox a control is currently located since the picturebox is not opaque as in VB6.
Can somebody please tell me how to do this in a good way in VB.NET?
This sounds like a job for the Panel control
For your issues with panels that you posted a screenshot for. Your panel is within another container, that's why it's displaying strangely. Try clicking the panel and cutting it (ctrl-x) then clicking the form header, and pasting it (ctrl-p). That will ensure it isn't within another control as sometimes that can happen in a way that isn't exactly obvious (like how you can see the control borders in your screenshot).

FlowLayoutPanel not showing all contents?

Very weird situation going on with a FlowLayoutPanel...
I have been dynamically adding user controls to my panel. This user control has a height of 105. If I have my FlowLayoutPanelwidth to only show 1 "column" of controls, it will only display 296 of them. The rest of the controls are grayed out at the bottom of the flowlayoutpanel. If I widen the flp to allow 2 "columns" of controls, I can see 592 of them, with the remainder grayed out at the bottom. I have gone in and resized the user control to make it shorter in height, which works in some respects (i.e. it works when I have two columns, but not just 1), and can go forward with this work-around.
So, I guess my question is, why does the FlowLayoutPanel behave in this fashion? It seems (based on what I saw) that there is a limit to how much data the FLP will show at one time.
Your comment just reminded me that when you're adding many controls to any container it is a good idea to do this:
YourPanel.SuspendLayout();
// populate panel with controls
YourPanel.ResumeLayout(false);
This in effect stops the container (panel) from re-rendering itself every time you add a control until you're done adding controls. In the very least your panel creation will be smoother and faster. Not sure if this might fix your issue or avoid the need for a hack with PerformLayout.
If you look at your Form's designer file you will actually see this in action in the InitializeComponent function.