Why is Visual Studio changing control positions & sizes automatically? - winforms

I noticed that when I've made small changes to existing Winforms code, numerous control locations are modified by Visual Studio automatically.
Example --
Original:
this.btnHelp.Location = new System.Drawing.Point(721, 444);
Changed:
this.btnHelp.Location = new System.Drawing.Point(556, 242);
Depending on the form there could be many of these. It looks like probably every control with a Size or Location property has been modified. Consistently made smaller, actually.
To be clear, no one made these changes manually. And oddly, I can't really detect any difference when running the app - though the changes seem numerically large enough to be noticed.
The only thing I can think of is a recent update from VS2015 to VS2019, but that's just a guess.

Related

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!

On using ConfuserEx combobox shows id's instead of values as dropdowns

I have used Confuserex to obfuscate my code which is using .net 4.5. Post compilation everything seems ok except for the behaviour of combobox (across all winforms i had in the project). The comboboxes are now showing id instead of the values as dropdowns. (Whereas these were running absolutely fine from visual studio in debug mode as well as the builds from the release mode).
In confuserex I have tried setting the preset to Aggressive, Maximum ... but same issue irrespective of whichever preset i use.
Not putting any code here as there is no issue with the code per se. This is most likely a issue in Confuserex.
Is this a known issue and does a solution exists? Please let me know if any further details are required for providing help.
There's no way to give you a singular answer, but perhaps I can steer you in the right direction:
In recently implementing ConfuserEx in a Winforms post-build event, I found that some third party controls were not displaying data correctly, or at all. Like you, I changed the preset from Aggressive to Normal, to no avail. I then went and excluded some of the methods that were binding data from obfuscation. It alleviated the problem in some cases, on a data grid view and list box, specifically. In those controls, I was receiving weird glitches like extra columns, cells rendered blank (with data present in the underlying object), et al.
All bets are off for third party controls with obfuscation - you'll never know if they will play ball or not. Sometimes you'll experience this with .Net controls as well. Obfuscation and Reflection also do not get along. Perhaps check your combo box data bind technique, and lift the obfuscation from the method where it is being populated with data, if nothing else. This is, of course, if you can live with this method being exposed. Here's one way to do it:
[System.Reflection.Obfuscation(Exclude = true)]
public void MethodYouDontWantToObfuscate()
{
//Your method code
}
Until just now I had a similar problem with WPF.
Our comboboxitems were in their own class. To solve the issue I added
[System.Reflection.Obfuscation(Exclude = true)]
in front of the class-declaration (like MoSSBerG suggested) and now everything works like a charm.

Converting multiple (and different) windows into tabs

Fairly new to WPF.
I'm tasked with converting our application with about ten different windows into a single-window, multi-tabbed application. I'd like your input on the most effective way of doing this.
I suppose I could do this the most-straightforward way -- copying and pasting a ton of code into the main XAML file. I imagine I'd end up with a gigantic file though, and would like to avoid that.
I should mention that the contents of each tab will be substantially different from each other.
There must be some element of WPF that enables this that I just haven't been able to find. Really appreciate any input.
In XAML there are user controls which you can use. That way, you could use one user-control per tab-content and let the main window only contain the tabview and tabitems and some minor logic code.
To achieve that, you can simply copy-paste most of your current window-code in one user control per window. The code base could remain almost the same (if there are no interactions between the windows at least).
There are quite many resources out there containing further details on user controls like this code-project article (a bit old, but the majority of its contents will still apply) or that MSDN one.

Lost a Control on a WinForm

I've been recursively refining a UI with visual Studio 2008, and I seem to have lost a control underneath the myriad layers of other controls. the project is checked into our version control software (I check in after I make a substantial enough change - for instance moving something around on or adding to the UI, or adding a method).
The refining of the UI has come directly from the boss, and he loves to move things around as we're discussing any changes that need to be made - which isn't that bad, I suppose. I check in before he starts faffing, and write down everything he does (in case we need to re-create it), then if nothing major has changed check the UI out again.
I suppose that I should mention that I'm using .Net 3.5 (because we can't upgrade to VS2010, yet) and C#, with a few custom controls (but most of them are the built-in .NET ones).
Somewhere down the line, I've lost a text box control. It's still listed in the Form properties window, and I can still select it from there. But when I look over at the form, there doesn't seem to be anything highlighted.
I've moved most of the controls around (where possible, as some of them are docked to sides of the form, or each other. Bad UI design, I know. But that's how the boss wanted it) and re-ordered them (send to back/front), and can get all the way back down to the background of the form (in most places). But I still can't find it.
At this point, I'm inclined to delete/remove the control from the form and start again with it rather than find it and move it into the new position. But, since I can't seem to find it, I'm not sure if I can.
Is it possible to delete the control in some way other than selecting it and hitting the delete key? I'd rather not have to jump back to an older version of the UI as I've made that many small changes, recently (and checked in after each one) and I have no idea when this text box got lost.
EDIT:
In case it's useful, here are some of the properties of the text box control:
Size: 356, 0
Location: 1, 1
Multiline: True
Text:
Dock: Fill
I've added text to the text property, and moved everything again and still can't find it. I've also been messing around with the Dock property in an effort to move it around the form to make it easier to find.
Also, most of the UI uses group boxes and panels, as I've found it easier to hide and disable/show and enable groups of controls as and when needed that way.
EDIT 2:
The text boxes properties are now (based on some helpful suggestions in the answers):
Size: 356, 150
Location: 150, 150
Dock: None
Multiline: True
Text: "Where are you?"
There may be few issue. Try these.
If u using team server along studio then u can right click the pending changes and see with older version where u see the changes done by previous vs current so u know want went wrong.
The control property visibility set to true. I.e: textbox1.visibility= true;
If the control is docked to fill then it wraps the other control under it. So try playin with the control properties.
Well, it has a height of 0 (Size: 356, 0). Change that to something meaningful and you will start seeing the control again.

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.

Resources