not able to set readonly property of textboxes in a panel in windows form to true in vb.net - vb.net

i want to enable the read only property of all the text boxes in a panel in windows forms to true during form load but its not working. i am using the below code.when i am debugging the code it skips that part.not sure why??
The below code does not work,it skips that part as if there are no text box controls in the particular panel.
Private Sub lockgroupcontrols()
For Each TextBox As TextBox In Pnltransaction.Controls.OfType(Of TextBox)()
TextBox.ReadOnly = True
Next
End Sub

Your code seems correct, so, I can only imagine that, if it skips the For Each, then you don't have any textboxes inside the PnlTransaction panel.
Sometimes this happens when you draw the Panel over preexisting textboxes. You think the controls are inside the panel, but in reality they are under the panel and you see them because the panel background is transparent.
Try to move the panel on a different place, drag&drop the textboxes over the panel and then reposition the panel.

You shouldn't use TextBox as name for your vars
For Each **TextBox** As **TextBox** In
try it with for ex.
...For Each **tBox** As **TextBox** In
tBox.ReadOnly = True....

Related

Set backgroundcolor of every form in vb.net

How can I set the BackColor of every form that exists in my vb.net (fw 4.7.2) project?
And yes, I could do
Form1.BackColor = ...
Form2.BackColor = ...
......
but that would be too messy then.
Open one of your forms in the designer, any form, doesn't matter
Click the form background
In the property grid, at the top, go to (Application Settings) then click the dots button in (Property Binding), find BackColor in the list of proeprties, click the dropdown next to it and click New at the bottom
Call your setting ThemeColor, pick the color you want for the light theme, such as White
OK everything
Open the designer for another form, go Application Settings/Property Binding again. This time don't click New, just bind BackColor to the existing ThemeColor setting
Repeat for all forms in your app
Add a button to the "Settings" form (or wherever you want to offer a toggle for the theme), and in its click handler write:
My.Settings.ThemeColor = Color.White
Add another button to the form, make its click handler set Color.Black
Run the application. Open one or more forms, including the settings form. Click one of the buttons to change the setting. All forms change color
You could:
For Each f as Form in Application.OpenForms
f.BackColor = Color.Red
Next f
at any point after you've opened a boatload of forms
.. or you'd just set the back color in the designer if you were designing a form and you wanted every form instance of that form that you created be red as soon as it was shown
I would have said you could create a class:
Public Class ColoredForm
Inherits Form
Public Sub New()
Me.BackColor = Color.Red
End Sub
End Class
And then in every form you add, open the designer and change the code so that it Inherits this form instead; but it's messing with the designer files (not everyone wants to do it, and changes could be lost if they were regenerated) and isn't actually any different to just.. setting the back color in the designer property grid. If you have some more involved behavior you want all your forms to adopt then consider an inheritance, but if it's as trivial as setting the BackColor, just do it in each form as a design time thing (If you have a lot of forms, can use find/replace for it)

disabling all command button inside the option group/ rectangle box using ms access vba

I have a userform with lots of command button inside and outside the option group/ rectangle box. What I need is to disable all the command button inside the option group/ rectangle box and retain only the cbutton outside the option group/ rectangle as enabled.
Here is my code:
Dim ctrl As Control
'loop through all form controls
For Each ctrl In Me.Frame106.Controls
'if control is a Command Button
If TypeOf ctrl Is CommandButton Then
'set caption to null
ctrl.Enabled = false
End If
Next ctrl
I did some research and got the same code but the code is not working on my side. Thank you in advance for you help.
I have done some testing, and maybe an easy way of solving this would be to place your command buttons on a separate form, instead of a group box, and then use this form as a subform on you main form. You can make this look visually identical to a group box.

Inherited panel is making controls disappear randomly

I have a class written that inherits a panel, and enables double buffering to it:
Public Class dblBufferPanel
Inherits Panel
Public Sub New()
'inherit a panel and add double buff to reduce flicker
'this will be used wherever a panel with gradient or bg img is needed
Me.DoubleBuffered = True
Me.ResizeRedraw = True
End Sub
End Class
The problem that I have been facing is that randomly while coding, the controls set within the various panels seem to "vanish" off the panel. Basically, the panel looks "empty" and there is no way to select the control from form design. I can however select them in the properties panel, but altering properties of these controls does nothing. The only solution I have found is that I close VS2010 and restart. Then, if I did not compile after noticing the controls "vanishing", they reappear upon opening the solution.
This seems to happen with any control, comboboxes, labels, listview, etc. What would be causing this?

vb.net textbox that won't let me highlight text

I'm working on an upgrade of a VB6 winforms project to VB.Net 2.0. On one form (and only this one form, out of about 25), my text boxes are acting odd.
When a user clicks into (focuses on) a textbox with a value in it, the cursor automatically goes to the beginning (left side) of the textbox and can only be moved with the keyboard arrow keys. I can't re-position the cursor with the mouse, and I can't highlight a section of text with the mouse.
The text box is not readonly and is both visible and enabled. In fact all settings are default as I've dragged out a new textbox and added it to the form and I get the same behavior.
Any ideas would be greatly appreciated.
OK, here is answer:
The startup form was set as an MdiContainer. This form had a split panel container that held another form for Application controls in panel 1 and the working forms in panel 2. When the working forms were loaded into panel 2, they weren't allowed to be top level as there was a .Parent attribute set to the split container panel 2. For some reason, the highlighting of text in a text box is disallowed unless the textbox is on a top level form, and since we couldn't get the working form to top level, we couldn't highlight the text. For reference, check this out.

Tabpage is empty after adding user control to vb.net tabpage

I am trying to display an usercontrol(has several panels one on top of the other panel) on tabpage. I am using below code to achieve this.
Dim ctrl As TechniciansControl = New TechniciansControl
TabControl1.TabPages(2).Controls.Add(ctrl)
The problem is that the control doesn't show anything. I verified the control is created correctly. The tabpage is empty. It works for other usercontrol which has only one panel.
Appreciate any ideas to fix this issue.
Make sure that the control is visible and, also, make sure that it's location is within the viewable client area of the tab control.