Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Here is my problem

 

Now, to have a "read only checkbox", we have to disable it.

I wanted to create my own Checkbox with a new property ReadOnly.

 

I have done it like that :

 

Imports System.ComponentModel
Imports System.Windows.Forms

'<summary>
'This class will implement a CheckBox with a ReadOnly property. THis will allow to have "white checkboxes" 
'that can't be modified
'</summary>

<Drawing.ToolboxBitmap(GetType(CheckBox))> _
Public Class ReadOnlyCheckBox
 Inherits CheckBox

 Private m_ReadOnly As Boolean = False
 '<summary>Will be raised when the ReadOnly property is modified</summary>
 Public Event ReadOnlyChanged As EventHandler

 '---------------------------------------
 '<summary>Will get or set the ReadOnly property</summary>
 '<value>True if the CheckBox is ReadOnly</value>
 <Description("Will get or set the ReadOnly property"), DefaultValue(False), Category("Behavior")> _
 Public Property [ReadOnly]() As Boolean
   Get
     Return m_ReadOnly
   End Get
   Set(ByVal Value As Boolean)
     If Value <> m_ReadOnly Then
       m_ReadOnly = Value
       OnReadOnlyChanged(EventArgs.Empty)
     End If
   End Set
 End Property

 '---------------------------------------
 '<summary>Will raise the <see cref="ReadOnlyChanged">ReadOnlyChanged</see> event</summary>
 '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param>
 Protected Overridable Sub OnReadOnlyChanged(ByVal e As EventArgs)
   RaiseEvent ReadOnlyChanged(Me, EventArgs.Empty)
 End Sub

 '---------------------------------------
 '<summary>Override the OnMouseDown to allow the ReadOnly behaviour</summary>
 '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param>
 Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
   If Not m_ReadOnly Then MyBase.OnMouseDown(e)
 End Sub

 '---------------------------------------
 '<summary>Override the OnMouseUp to allow the ReadOnly behaviour</summary>
 '<param name="e">A <see cref="MouseEventArgs">MouseEventArgs</see> that contains data of the event</param>
 Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
   If Not m_ReadOnly Then MyBase.OnMouseUp(e)
 End Sub

 '---------------------------------------
 '<summary>Override the OnKeyDown to allow the ReadOnly behaviour</summary>
 '<param name="e">A <see cref="KeyEventArgs">KeyEventArgs</see> that contains data of the event</param>
 Protected Overloads Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
   If Not m_ReadOnly Then MyBase.OnKeyDown(e)
 End Sub

 '---------------------------------------
 '<summary>Override the OnKeyUp to allow the ReadOnly behaviour</summary>
 '<param name="e">A <see cref="KeyEventArgs">KeyEventArgs</see> that contains data of the event</param>
 Protected Overloads Overrides Sub OnKeyUp(ByVal e As KeyEventArgs)
   If Not m_ReadOnly Then MyBase.OnKeyUp(e)
 End Sub

End Class

 

As you can see, the code is very simple. I have created my control in a separate DLL. To test it, I have created a new project with a simple form. Set a normal TextBox and my new "ReadOnlyCheckBox".

I run the project and it is ok.

Note that for the test, the form windows must be visible at design time.

I decide to test my property and set ReadOnlyChecBox1.ReadOnly = true on the designer.

I compile, everything is ok.

I run the project and I have the following error :

"An error occurred while loading the document. Fix the error, and then try loading the document again. The error message follows : The designer cannot be modified at this time." And indeed VS.NET (2002) has tried to modify the designer.

Why ?

What's happening ?

How can I solve that ?

 

 

I have attached my simple test project if anyone have an idea...

 

 

Also notice that I have tried to do exactly the same in C# and it seems to work properly...

rocheckboxtesting.zip

Jarod
Posted

Umm... because I was searching for a property called ReadOnly and that I missed this one..... :">

Ok thanks, this one does the job. :-D

By the way, I'd still like to understand my VB problem...

Jarod

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...