groupbox not becoming visible - vb.net

I'm having a problem getting a second GroupBox visible, this is my code
Me.grpCallerDetails.Location = New Point(x:=0, y:=2000)
Me.grpCallerDetails.Visible = False
Me.grpCallDuration.Location = New Point(x:=0, y:=0)
Me.grpCallDuration.BringToFront()
Me.grpCallDuration.Visible = True
Me.Refresh()
the grpCallDuration.Visible property remains False even after setting the property to True.
Initially the settings are:
Me.grpCallerDetails.Location = New Point(x:=0, y:=0)
Me.grpCallerDetails.Visible = True
Me.grpCallDuration.Location = New Point(x:=2000, y:=0)
Me.grpCallDuration.Visible = False
I'm moving the location of the group boxes around so that they don't overlap, but nothing, so far is working.
What is going on?

OK, I solved it.
The problem was grpCallerDetails was Docked Fill, and grpCallDuration remained as a child of that GroupBox no matter what I did.
I just changed the Dock to None and moved grpCallDuration out on its own...

Related

Unable to change Panel Visibility

I'm having a panel inside another panel. Now I need to alter inner panel's visibility based on certain condition. But I'm unable to change. It always remains to False. Here is the code I'm trying to:
PnlTagFolders.Visible = True 'Always remains False.
PnlTagFolders.BringToFront()
Here is the screenshot for reference:
You can't make a Panel visible if the parent Panel isn't visible. So make sure the parent Panel is visible (.Visible = True).
true if the control and all its child controls are displayed; otherwise, false. The default is true.
source: Microsoft Docs
See the following:
ChildPanel.Visible = False
ParentPanel.Visible = False
ChildPanel.Visible = True
Debug.Print(ChildPanel.Visible) 'False
Another example:
ChildPanel.Visible = False
ParentPanel.Visible = True
ChildPanel.Visible = True
Debug.Print(ChildPanel.Visible) 'True

Failing to select or set focus to a custom control

I have the following code to select a custom control. But it does not want to set the active control to 'uPnlEntryOptions'. I have tried using control.select as well, same result. I have also tried
ActiveControl = uPnlEntryOptions
Code
uPnlEntryOptions.Visible = True
uPnlEntryOptions.Refresh()
uPnlEntryOptions.Select()
uPnlEntryOptions.Focus()
Debug.Print(CStr(uPnlEntryOptions.Focused))
Debug.Print(CStr(uPnlEntryOptions.CanFocus))
Output
False
True
The Focused property is true only if the control has the focus, not a sub-control.
Calling Select (or Focus?) on a UserControl will select the first child control. Afterwards the UserControl.ContainsFocus = True since the focus is WITHIN the UserControl, but the UserControl.Focused = False, since the UserControl itself isn't the focused control.

RadioButtons Highlighting Incorrectly

On my form, I have 4 RadioButtons, each with its appearance set to Button. In my program, I change each of these RadioButton's ForeColour, BackColour and AutoCheck status, as below:
ARadioButton.AutoCheck = False
ARadioButton.BackColor = Color.FromKnownColor(KnownColor.ControlLightLight)
ARadioButton.ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
However, later on, I reset these properties back to default:
ARadioButton.AutoCheck = True
ARadioButton.BackColor = DefaultBackColor
ARadioButton.ForeColor = DefaultForeColor
My issue is that instead of the entire button being highlighted, only the outside is, as shown in the images below.
Originally:
After changes are made and RadioButtons reset to default using code above:
I know this may seem trivial, but I would like the entire RadioButton to be highlighted when the user clicks on the RadioButton, not just the outside.
Is there a way I could somehow reset this?
Try setting the BackColor property to Color.Transparent

How do I make a group box's text bold but not the text of controls contained in it?

I went and created a tab containing a good amount of controls, most of which are contained within what I'll just call the top-level group box. Now I decide I'd like the text of the top-level group box to be bold, but nothing else. When I set the top-level group box's font to bold, however, all of the controls contained within it become bolded as well, which is what I don't want. I can set each individual control's bold property to false, but it seems like there should be an easier way to do this. Any ideas?
I'm probably missing something obvious, like a group box property that is staring me in the face--and apologize if this turns out to be the case.
Thanks in advance for any help.
You could bypass the problem by placing a label over the caption for the GroupBox, but I wouldn't necessarily recommend this.
A better solution emerges once you understand what is happening and why it is happening. The issue is that a control's font (among other things) is an ambient property, meaning that child controls inherit their parent/container control's properties. So if you set the GroupBox to use a bold font, all of its child controls automatically inherit the bold property by default.
The key there is, of course, by default. Ambient properties only apply if you don't explicitly set the properties of the children to something else. If you don't want the child controls to be bold, select them all and turn off bold. The settings of the parent/container will no longer override the new custom settings.
To make things even easier, you can add a Panel control to your GroupBox, dock/anchor it to fill the entire client area of the GroupBox control, and set it to use a standard, non-bold font. Then, the rules of ambient controls stipulate that the child controls you add to the Panel will not be bold by default. This way, you only have to change the font property of one control as opposed to every child control that you add to the GroupBox.
The reason that this is better than trying to add a Label control over the GroupBox caption is because a GroupBox is designed to contain controls. You can take advantage of the docking and anchoring properties to make sure that everything gets arranged correctly, and you won't have to fight the designer when doing so to make sure that your custom Label correctly covers up the default label drawn by the GroupBox control. Additionally, you won't run into Z order issues or have other redrawing problems rear their ugly heads at runtime when, for example, the Label control gets accidentally hidden behind the GroupBox and no one can see it (and a host of other potential snafus).
I came across this old question when searching for the same, and realised it could be solved in code without adding a separate control just to overcome the ambience issue that Code Gray mentions in his answer.
Add an extensions in a module like so:
<Extension()>
Public Sub UnBold(Of T As Control)(cc As Control.ControlCollection)
For Each c As Control In cc
If Not TypeOf c Is T AndAlso c.GetType.GetProperty("Font") IsNot Nothing Then
Dim RegularFont As New Font(c.Font.FontFamily, c.Font.Size, FontStyle.Regular)
c.Font = RegularFont
ElseIf c.HasChildren Then
UnBold(Of T)(c.Controls)
End If
Next
End Sub
Then unbold all the controls in all the GroupBoxes on a form (including any child GroupBoxes) by using as follows in the form's OnLoad event:
Me.Controls.UnBold(Of GroupBox)()
Or for all controls in a single GroupBox (again, including any child GroupBoxes):
MySpecificGroupBox.UnBold(Of GroupBox)()
With the proviso that if you actually want control within the GroupBox to actually stay emboldened you will have to set that in code after calling the extension.
Consider bypassing the problem by placing a label over the GroupBox's text area and make the label's font bold.
I did it once and even used a CheckBox (for enabling/disabling the whole group). Worked like a charm.
Place all of your controls inside of a ContentControl and reset the font parameters
<GroupBox Header="Group" FontSize="16" FontWeight="Bold">
<ContentControl Margin="0" FontSize="12" FontWeight="Regular">
...
...
...
</ContentControl>
</GroupBox>
Programatically you can do it in order. Assume you want to make font style bold in groupbox but not in child controls. First set the font to a new Font in child controls, in this case you can pass groupbox font property. Then change groupbox font style to bold.
var grpBox = new GroupBox()
{
Text = "",
Width = 780,
Height = 70,
Parent = panel1,
Dock = DockStyle.None,
AutoSize = false,
Visible = true,
Location = new Point(20, grpY)
};
var label = new Label()
{
AutoSize = true,
Parent = grpBox,
Enabled = true,
Name = "label" + btnNum++,
Location = new Point(5, 50),
Text = "",
Font = new Font(grpBox.Font, FontStyle.Regular)
};
var txtBox = new TextBox()
{
Width = 550,
Height = 23,
Location = new Point(65, 20),
Name = "txtBox" + btnNum++,
Parent = grpBox,
Enabled = true,
Tag = label,
Font = new Font(grpBox.Font, FontStyle.Regular)
};
grpBox.Font = new Font(grpBox.Font, FontStyle.Bold);

VB.Net Forms - MDI forms not locating correctly

I have a problem with MDI forms and their location. I have a container form within which I open several child forms. Also note that in the container form I have a ToolStrip at the top and it is also docked to the top. In each of the child forms I have set the following properties. I have set them at design time as well but it wasn't working for some reason so I put them in the form_load event as well.
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Dock = DockStyle.Fill
ReSizeAndArrange(Me.Width, Me.Height, False)
The function ReSizeAndArrange is called on form_load and form_layout events. The problem I am having is that the child forms do not fill the remaining space correctly or for that matter the entire parent form. When I step through, here are the coordinates I am getting for the child form.
frmContainer.Size {Width = 972 Height = 972} System.Drawing.Size
me.Size {Width = 968 Height = 901} System.Drawing.Size
frmContainer.ToolStripMain.Size {Width = 954 Height = 67} System.Drawing.Size
frmContainer.Location {X = 90 Y = 22} System.Drawing.Point
me.Location {X = -9 Y = -36} System.Drawing.Point
Shouldn't the Me.Location be 0,0? The numbers add up on the sizes I think. The 4 pixel difference can perhaps be explained by the border, however, the location is unexplained. Can anyone decipher this?
OK, I solved the problem myself simply by setting the location of the form to (0,0). It still doesn't answer the question, but it is a workaround.
It's because 0, 0 doesn't put constraints on the form size/layout. It allows it to decide. Any value you put in there forces the form to conform to YOUR specs. 0, 0 isn't a work around, it's the "you decide this yourself form" way of doing it.