Form1 [Design] loads a blank template after renaming an event handler - winforms

In VS2013, I renamed one of my button event handlers and wanted to drop into the [Design] to change the property. I got a huge warning telling me that things are not as they seem (expected, since I changed the delegate's name) so I hit Ignore and Continue. This is the first time I've hit this button.
To my horror, what I saw was ... a blank template as opposed to my original winform. I have backups of my code, so I'm not too worried, but I was wondering how I'd go about restoring my Form1.cs[Design] without going back a code rev.
This is what my [Design] looks like now:

Did your error say this?:
By renaming the delegate in your code file, you hung the designer out to dry. Everytime you switch to the designer tab, it parses InitializeComponent() to draw your controls for editing, and since the reference to the original callback doesn't exist anymore, the designer doesn't know what to do when it encounters the unknown reference. By forcing its hand, it simply craps out like it was telling you it was going to do. The blank panel is just a result of it failing and drawing nothing.
Pop open your Form1.Designer file and find where the button's properties are set. The unknown reference is probably highlighted in red. Change the name to whatever you changed in your other file. Here's an example, but with a panel instead of a button:
And then your designer should return to normal. No worries about rolling anything back, it's a minor fix.

Related

WinForms - Can't add picture to picturebox

I pretty much just started using Windows forms and I'm trying to add a picture to a picture box. First I tried the most obvious way, that is - clicking on the little arrow in the top right corner of a picturebox and clicking "choose image" in the small dialog box, but no matter what I do, the "choose image" button does utterly nothing. I know it should open some dialog box where I could choose my picture, but litterally nothing happens, not even an error message pops up.
Next I tried importing the picture through the properties of the picturebox, but after clicking on the three dots next to the image property an error message pops up, saying "value cannot be NULL, Name o parameter: docData".
I tried following this answer (How to attach a resource (an image for example) with the exe file?) and going to the properties of my project and then to the resources tab, but I have this tab completely empty, saying just that my project does not contain any default resources and a "click to create them" button. However when I click it, another error message appears saying "system cannot find the file. Exception based on value HRESULT:0x80070002"
I guess the problem must be somewhere in my resources file (which might be missing or whatever), but I have a default .resx file there that I haven't touched since the creation of this project which I had thought should be fine.
Afterall I pretty much just started with WinForms and I don't have much clue what's going on and this is quite a significant setback for me. I would be grateful for any help.

WPF Designer crashed and stopped showing Test Data permanently

It happened again. My test data is not shown any more. I see only class and property names. Restarting does not help this time. Retracing neither.
I've been rewriting my whole project since that happened.
Now I tried to use Test Data class to address it from custom user controls so it would look like:
...d:DataContext="{Binding Source={DynamicResource TestData}, Path=Emploee}"...
//in resources
<main:TestData x:Key="TestData"/>
Not like it was previously:
...d:DataContext="{DynamicResource TestEmploee}"...
//in resources:
<shar:PVEmploee x:Key="TestEmploee" Name="Alpha" Surname="Omega" Phone="77777777" PVProfession="{DynamicResource TestProfession}"/>
<shar:PVProfession x:Key="TestProfession" Name="Some obnoxeously long profession name"/>
And right after those changes in this control (I've done it previously few times already to other controls, I've copied from previous project version) the designer crashed. Now I see
this ridiculousness, instead of test data
I am frustrated. Am I supposed to restart it again? Or there could be some way to fix it.
Answer to almost not realated question Actually worked well (the question was - how to crash a Designer =D ). If I kill designer in Task Manager, and click 2nd option in Studio. The Designer loads pretty well in a right way. All my Test Data right there. Or I found later that I can click small document icon on designer bottom to reload it with or without user code.
After a few such resets it started behaving. Marvelous!

VS2010 Winform designer alterate decent code

I'm encountering a problem with the WinForm designer. I made a new UserControl, I added a DataGridView, some other elements and a TreeView. With the gui I named all those new components. Now it's time to code that stuff and I realise that the designer missnamed my node of my TreeView. The Designer also added new columns from my DataSource even if it was set to AutoGenerateColumn to false. I though: "Well time to clean some Designer crap again..." and I cleaned that stuff up in the InitializeComponent function (I know it's labeled "Do not modify with the code editor" but... do I have the choise?
Anyway, my problem is : When I go back on the Design view, the VS Designer seems to regenerate the code back but not even how it was. Now the designer declares my DataGridView and my TreeView as local members of InitializeComponent function. I can easily repair and undo my changes but I would like to understand and know if there is a way to disable the auto code generation of the designer.
Also, I tried to make another function which have all what I need so the designer don't screw it up and call it into the initialize component. This solution works at run time but not on Design view. I'm kinda low.
As far as I know, the short answer is no. If something is marked as Do not edit due to code generation., then do not edit it :). I would suggest reading up on partial classes, as that is how you can modify classes without actually messing with the auto generated code. In your case, you will need to go into the designer and fix everything there so that the auto generation works as you expect it to.

IsKeyboardFocused is always False inside OnRender()

I'm trying to make my own custom text editor for my program, which so far does syntax highlighting. It can't even edit text yet.
I've run into a snag when trying to display my caret.
In my OnRender() method, I use IsKeyboardFocused to check to see if I have keyboard focus, which if I do, then it goes ahead and draws my cursor.
I have told the keyboard via Keyboard.Focus(MyCustomTextEditor) to focus on my control when I click on it with my mouse, and when I intercept it using a GotKeyboardFocus event handler, I can verify using debugging messages that the focus was passed successfully.
However, no matter what I do, I can't seem to make IsKeyboardFocused = True inside OnRender(). I placed Debug.Print()'s at the beginning, end, middle, and every other place imaginable inside OnRender(), with the results always being False.
My method seems pretty straightforward. I just don't understand what I could have left out. Thanks for your time reading this!
Have you tried using FocusManager.FocusedElement to figure out what element is focused when you're expecting your control to have focus? That should give a few clues.
Shot in the dark, is OnRender() being called again after control load, or are you only checking on init? I recall focus issues involving setting focus on a control during the Loaded event, only to have focus revert afterwards.

Navigate to Event Handler Does not work in WPF Application

I am studying a code base developed using .NET WPF. I am using Visual Studio 2008 IDE. In the XAML code, I have a line as follows:
<MenuItem Header="About" Click="Main_Window_ContextMenu_About_Click">
Clicking right mouse button, I see a option called "Navigate to Event Handler". However, clicking it does not take me to the Event Handler definition. In fact, this action seems to have no effect.
Why is this happening and how can I fix this issue?
If you're using ReSharper, hit F12 while the cursor is on the event handler name (assuming you're using ReSharper's default shortcuts)
That shortcut in the XAML designer isn't very reliable - it only works when the event handler method is defined in the code-behind for the XAML file. For example, if you have "Window.xaml" it will only work if the handler is in "Window.xaml.cs".
This breaks, for example, if the event handler is defined in a second partial class file like "Window_EventHandlers.cs". This particular one even generates a new blank event handler in the code-behind file which promptly fails to compile on a duplicate method definition - yuck!
If you can't find it, your best bet is probably a solution or project-wide search for the method name.
This is a known issue. There are several ways to fix it, including re installation.

Resources