I i am unable to see the design view of a winform app
Errors are:
One or more errors encountered while
loading the designer. The errors are
listed below. Some errors can be fixed
by rebuilding your project, while
others may require code changes.
The event Click is read-only and
cannot be changed.
at
System.ComponentModel.Design.EventBindingService.EventPropertyDescriptor.SetValue(Object
component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAttachEventStatement(IDesignerSerializationManager
manager, CodeAttachEventStatement
statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)
Try the following helpful links:
http://connect.microsoft.com/VisualStudio/feedback/details/329327/designer-error-when-implementing-a-baseform-event-for-a-control-on-an-inherited-form
http://www.google.co.uk/search?hl=en&source=hp&biw=1600&bih=1075&q=the+event+click+is+read-only+and+cannot+be+changed&aq=f&aqi=g1&aql=&oq=&gs_rfai=
Of course, I'm only guessing.
The reason is that the default in the form designer is to make these Friendly or Private. You need these to be protected or internal. You can just change this and the designer will not overwrite this change.
Related
I am developing an application using Visual Studio 2019 and I am designing winforms.
Visual Studio commonly crashes when I am creating the forms by freezing, and recently my designed winform has somehow disappeared (even though I saved it). When i open it it shows as the default winform that is shown when a new one is created:
When I browse the solution explorer it seems that I can still see all the components I had added to the form:
Finally, when I try to restart and manually add the components back, I get an error message saying that the component can't be added due to duplication - which is probably because they are somehow still there (as shown in the solution explorer) but the data has been corrupted somehow:
If anybody has any idea of how to recover the data and the winform, I would very much appreciate it. If any additional information is required, please let me know. Thanks!
According to your description, first, the controls actually exist, but they are not
displayed in the design window.
You can try to check whether the. add statement of each control added to the window still
exists in the .Design.cs file.
If not, you can add it manually.
Second, solution explorer shows the missing components, but there is an error in adding
components. It means that only the declaration of this control in the .Design.cs file does
not assign a value to this control. You can delete the declaration of the component in the
.Design.cs file, and then add the component in the design interface.
Result:
I am currently putting together a prototype for a custom tab control we are trying to implement in c# for .Net 2.0. As the control itself works fine, we are now trying to integrate full design-time behaviour. This does include a custom CodeDomSerializer at a certain point to tell that the tabs have to be added as well. This does work fine now (after a longer process of trial and error).
But there is a problem left that seems to have to do with Deserialization. The designer code is created just fine and the designer looks just the same. But when I hit rebuild project, the forms designer sometimes show this error:
The variable 'piTabControl1' is either undeclared or was never assigned
http://msdn.microsoft.com/en-us/library/4008y84t(v=vs.80).aspx
The error does not appear every time, but it always happens when I have just added a new tab. The error points to this line:
this.Controls.Add(this.piTabControl1);
But I know that the variable is assigned, as this is in the code a few lines before:
this.piTabControl1 = new pdfforge.PdfCreator.Controls.PiTabControl();
The application also does compile and run with everything shown properly. If I close the Designer and reopen it, it is also shown without that error. So I suspect that there is something going wrong when Deserializing the code or updating the designer.
I have uploaded the full solution here, because it is just too much code to paste here:
http://www.chinery.de/dateien/TabControlTest.zip
To reproduce this in the project, you will first have to recompile the whole solution for the custom controls to be compiled. Then you can open Form1 and hit rebuild. If it does not produce the error, you can try adding or deleting tabs from the tab control.
I really don't have a clue how to approach this, because I can't tell the inner state of the Forms designer. I am very thankful for any hint. I can also add specific code snippets here if requested.
In a windows form I am populating a combo box with the following code.
this.JackStudTypeComboBox.Items.AddRange(ViewController.GetJackStudMaterialType().ToArray());
When I attempt to open the Form Designer I get the message that the ViewController type is not found.
The ViewController class is located in the same project as the form. Compiling the project has no issues, and running the project results in the expected behaviour.
So, how do I convince the Form Designer to locate this particular class, or to ignore the fact that it is unable to find it or do anything useful with it when in static design mode?
Don't do that.
You should never put any custom logic in InitializeComponent().
Move that to the constructor and everything will work fine.
I've been having some issues with the propertygrid. Namely:
The behavior is not the same when i'm using a the propertygrid in the visual studio designer, versus at runtime, also while debugging.
A few to note (this is using a form in the designer, and editing a custom textbox, versus embedding a propertygrid into a form, and attaching it to the same custom textbox)
When I have multiple object selected in the designer, and I set a property (custom type, with converter) I'm getting a null reference exception. When I used the 'SelectedObjects' field at runtime, I don't get the exception. If I attach the debugger to the designer, the exception will not happen, and my property setting will work correctly.
I implemented my own expandableobject converter that does property ordering. My properties show up in the correct order when I'm running my application, but they still show up in the default order when using the visual studio designer.
Is there any resources out there that can help explain why these behaviors are happening?
Thanks!
Are you referencing any classes outside of the current assembly (or outside the solution even more-so)?
The designer is not nearly as good as loading those external dll's. There are situations where the designer will know that you're deriving from ExpandableObjectConverter, but cannot load your specific base class, and in the end, it just loads the generic converter. Try loading all of your bases classes into the current assembly and see if that makes a difference.
I've created a custom control using C#, .Net3.5, and Visual Studio 2008.
I'm then adding that control to another control by dragging it from the toolbox.
After doing this when I try to compile I get an error as follows:
Error 1 Warning as Error: Field 'MyNamespace.MyControl._myCustomControl' is never assigned to, and will always have its default value null
Looking at the Designer.cs file this is due to the fact that VS never generates the following code:
this._rgReportGallery = new MyNameSpace.MyCustomControl();
The field itself is there, and the code to add it to the control I'm putting it in, just the instantiation code is missing.
I can add that code manually and everything seems to work, but as soon as the designer.cs file is regenerated it goes missing again.
I've even successfully added a different custom control and had that code get generated.
Does anybody know what could be causing this?
I was having this issue and a reply here helped me find the issue, I was using the "internal" keyword for both my component accessibility and the constructor accessibility. As Brent mentions in a couple posts above mine, VS designer apparently has issues generating an instantiation line with anything except a public constructor, so never make a custom user control where the class accessibility and constructor(s) are anything but "public."
By the way, this occurred for me on Visual Studio 2005, and it doesn't surprise me that it also would happen on Visual Studio 2008. It likely happens on earlier versions of VS as well.
Have you adjusted the constructor of the custom control in any way? The default constructor for controls is a parameterless one, and I know I've had trouble in the past when creating a constructor for my controls that requires parameters. In those cases I always provide two constructors. That way the parameterless one remains for the design mode in VS.
Also make sure your UserControl's constructors are public. I've had issues with internal UserControls and the VS2008 SP1 WinForms designer code generation. It failed to generate the allocation line like you mentioned.
Even though the .Designer.cs files look like simple code, playing around in that code is very risky because it can easily break the Windows Forms Designer. I've heard a lot of people just abandoning the WinForms designer because they say it does not work. It's indeed easy to break, but if you don't try to play in the .Designer.cs file, it works like a charm.
If you have edited the Designer.cs file manually, it might explain why it keeps rewriting itself wrong. It's hard to know how to fix it though. If your UI is not too hard to redo, I would just redo it (whatever is in your main .cs file will be untouched). Otherwise you can look at a similar form to see a model of how exactly it should be formatted (the order of the statements is important).
Do you have the latest service pack for Visual Studio 2008? This usually happens when you don't have the latest service pack.