473,507 Members | 4,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to disable controls in a form

please help,

i'm trying to find a simple & easy way of enabling & disabling (generally
making them readonly) most of the controls in my form.
Cuz i want to create a form, for the user but only a readonly form (with no
write access).

But i cannot find any easy way of doing this,
i've tried using the OnEnabledChanged() event, & exposing such other custom
events.
But to no avail. Please help.

What i've also tried is having some methods to loop through the control
collection, & then disabling the controls one by one - slow & have to
consider various control types.

I'm sure i'm missing something very simple here, cuz this is something most
application would need - a readonly view of a screen.
But how can this be achieved????
Nov 21 '05 #1
8 4970
Hi Antuane

Me.Enabled = False on your form will disable all of its contained controls -
is that what you want?

Nigegl Armstrong

"Antuane" wrote:
please help,

i'm trying to find a simple & easy way of enabling & disabling (generally
making them readonly) most of the controls in my form.
Cuz i want to create a form, for the user but only a readonly form (with no
write access).

But i cannot find any easy way of doing this,
i've tried using the OnEnabledChanged() event, & exposing such other custom
events.
But to no avail. Please help.

What i've also tried is having some methods to loop through the control
collection, & then disabling the controls one by one - slow & have to
consider various control types.

I'm sure i'm missing something very simple here, cuz this is something most
application would need - a readonly view of a screen.
But how can this be achieved????

Nov 21 '05 #2
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
Me.Enabled = False on your form will disable all of its contained
controls -
is that what you want?


This would prevent the user from moving or closing the form. Consequently
it's better to put everything in a panel, for example, and then disable the
panel only and keep the form enabled.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Hi Herfried,

Are you sure...? That's the case for MDI Children, but I don't think it is
for a top level window...

Nigel

"Herfried K. Wagner [MVP]" wrote:
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
Me.Enabled = False on your form will disable all of its contained
controls -
is that what you want?


This would prevent the user from moving or closing the form. Consequently
it's better to put everything in a panel, for example, and then disable the
panel only and keep the form enabled.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
Are you sure...?
Yes.
That's the case for MDI Children, but I don't think it is
for a top level window...


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Hi Herfried

I've built a minimal app:

When I run this I can move and close the form - is that not the case for you?

Regards,

Nigel

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(96, 88)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(96, 120)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(96, 152)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 2
Me.Button3.Text = "Button3"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 262)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Enabled = False
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Public Shared Sub Main()
Application.Run(New Form1)
End Sub
End Class


"Herfried K. Wagner [MVP]" wrote:
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
Are you sure...?


Yes.
That's the case for MDI Children, but I don't think it is
for a top level window...


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
I've built a minimal app:

When I run this I can move and close the form - is that not the case for
you?


Yes, I can now move the form. Really interesting... Move the 'Me.Enabled =
False' to the form's 'Load' event handler and you won't be able to move it
;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Hi Herfried

I know this has got a bit off topic, but am I the only one who thinks the
difference in behaviour of Enabled = False depending on when it is applied is
strange? I agree that adding a Panel and 'disEnabling' it is a better
approach though...

Nigel

"Herfried K. Wagner [MVP]" wrote:
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
I've built a minimal app:

When I run this I can move and close the form - is that not the case for
you?


Yes, I can now move the form. Really interesting... Move the 'Me.Enabled =
False' to the form's 'Load' event handler and you won't be able to move it
;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
"Nigel Armstrong" <Ni************@discussions.microsoft.com> schrieb:
I know this has got a bit off topic, but am I the only one who thinks the
difference in behaviour of Enabled = False depending on when it is applied
is
strange?


That's really strange (and certainly a bug, I think)!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2456
by: Blnukem | last post by:
Hi All I'm new to javascript and was wondering if someone can help me with this I want to disable my second and third drop-box if the first one is selected to "Closed" I think I'm close but just...
7
9800
by: Saintor | last post by:
What I do now is I put a value in the tag property, and using the form_current event, I run through all controls properties until the ones with the required tag value are met. Sound OK in theory,...
2
3675
by: buran | last post by:
Dear ASP.NET Programmers, I have a web user control (a search menu) which has 2 validation controls (one for input and another for the search criterion). I am including this search user control...
9
24128
by: junlia | last post by:
Does anyone how how can we disable the auto-postback feature in asp.net page? I have to use a server side control in the page, but the auto post back feature in it causes problems for me. Please...
7
22979
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable...
5
2280
by: Edwin Knoppert | last post by:
I have a div which holds controls. I'm looking for a way to disable all controls but *without* setting each control enable state. Same to style>display i'm looking for a disable method. Do i...
2
565
by: Larry | last post by:
Is there a way to disable all the controls the instant any auto-postback controls are changed (resulting in a postback that takes a couple seconds), so that the user can't continue changing other...
0
1789
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a problem while developing some webpages.The Problem is that:- How We Can Disable The Controls Of One Web Form From Other Web Form In Asp.net? Explanation:- There Should Be Two...
5
11253
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
8
5078
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.