C# Winform Control Dimensions Strange Out Of Editor? - c#

I've run into this weird sizing issue for my windows form application when run. Now in the designer the program looks like This1 (can't upload more then 2 links so look in comments). However when I run it from visual studio it looks like This (notice how all the controls are closer together, the picture box is automatically wider and taller & the picturebox in tileset subform is larger).
When built and run outside of Visual Studio from the bin\debug folder, it looks perfectly fine (as it would in Visual Studio like This). However I recently changed the build folder to one with a shorter path and when I now run from there the entire form looks much larger and the picturebox is again scaled in this2 (can't upload more then 2 links so look in comments).

take a look at this similar question.
Did you try to set the dpi awareness in the manifest as in the question above?
Also be sure, you run both (visual studio) and the .exe from
bin/debug as the same user (ex. run as Administrator).
And if it's not to late, consider a change to wpf, it responds much better to the different screens and different resolutions - at least in my opinion and experience.

Related

Adding any control to an existing C# Windows form corrupts the display

I'm using Visual Studio 2022 Community Edition w/ .Net 4.8 but the same behavior presents itself with Visual Studio 2019 Professional w/ .Net 4.6.1
What is happening is that I can clone a new Feature branch from Git to my local system and when I launch it everything is fine. The main application form presents itself just fine and I can get to all of the buttons, dropdown lists, file selectors just fine. The minute that I had any new control to the form when I subsequently launch the application the form is cut in half and I can't get to any of the controls and maximizing the form doesn't help either. When I inspect the designer code things have been drastically moved around in the post modification file as compared to the original. I've included sample information--
Original Form Display
Post Modification Form Display
Designer Code Compare Sample
A team member can take the same code base and add controls without any problems. Additionally he took my codebase which runs fine on his system compiled it and sent me the executable and when I launched that executable I had the problems with form display that my solution exhibits.
One final not thinking it was my laptop I got a brand new laptop and I'm still seeing the issue. I also created an AWS EC2 Instance and tried it there with the same behavior.
We're all stumped here none of us has ever seen behavior like this. We're hoping that someone in the Community has seen this sort of thing before and can shed some light on the issue.
Thanks,
Bill

testrun of form in visual studio c# shows a visible small scale version of it

i recently installed visual studio 2015 and made my first code in c#.
('maximized' for window state at the properties of the form)
everything went fine (comilation and testrun without errors) until i attempted to load one of the example tutorials, which i interrupted during loading.
after that i compiled and started my self coded application again from within visual studio. this time the output of the form was, unlike before, displayed half its size.
all the buttons including the window of the form appeared half its original size.
but when i executed the comiled application outside of visual studio (without it actually running) the application started in normal scale as intended.
this effect happens for this specific project only. if i start a new project the compilation & testrun will show a form scale as expected.
so my question: is there any magical setting that i have to change to end this nightmare ? i dont like to start all over again with a new project. i had set up 72 different button already. each buttonpress causes a different
SendKeys.Send("");
to be executed.
Check the Form's AutoScaleMode property!
The default is Font:
Controls scale relative to the dimensions of the font the classes are
using, which is typically the system font.
If that won't help do try to create a new project and copy the relevant cs-files into it!
In theory there is a zoom option in the VS designer, but at least in the Winforms desiner the shortcut does nothing for me.. It probably is for the WPF designer.
You did tag the question correctly and it is indeed about Winforms?

How can I make Visual Studio use my updated icon for my NotifyIcon?

I am totally stumped by this issue and I do not know what to do.
I have created a simple C# Windows Form application using Visual Studio 2012 Premium. I have a small program that starts up and creates a NotifyIcon in the system tray. On click of the tray icon, a context menu is displayed and it shows a few menu options (Options, About, etc.), where each option displays a form. I have added two icon files (.ico) via the Resources by right clicking on my Project item, Properties, Resources. I programmatically change the Icon of my NotifyIcon, alternating between the two different icons. My problem is that my old icons keep displaying, instead of my new ones that I've added to the project. To be clear, my issue is that OLD icons keep displaying--everything is working and there are no errors, it just doesn't show my latest icons.
The way I'm changing the icons in code is using:
notifyIcon.Icon = Resources.IconA03312014; //or the other one; the numbers are the date
I initially made my icons and used those and later decided to change them a little bit--I changed some colors, etc. So then I removed the old icons from my project by clicking the Exclude from Project option. Then I added my new icons, which had different names. Then I updated my two code references that load the icons to use the new names. No matter what I do, my new/updated icons are not displayed!
Whether I run the program in Visual Studio in Debug or Release mode, it does not matter. I can clean the solution, rebuild, and then run the executable directly by clicking on it in Windows, and no difference. Old icons are shown.
I have followed different sets of instructions online that explain how to clear the Windows 8 icon cache (three different methods). I have cleared the cached Notification tray icons as well, using two different methods.
Basically, I cleaned my solution and then closed Visual Studio. I kill all explorer processes, run ie4uinit.exe -ClearIconCache from the command line and delete the IconCache.db file. Then I delete the notification icon cache by editing the registry following instructions similar to these (http://www.sevenforums.com/tutorials/13102-notification-area-icons-reset.html). Then I shutdown the computer. Upon starting backup and rebuilding my solution and running, the old icons are still there somehow. The physical .ico files for the old icons were deleted long ago. Each time I've added new icons to my Resources, I've created new icon files from scratch (using icobundl.exe) and named them uniquely by including the date in the name. I am aware that Windows, and apparently Visual Studio also, like to cache icons and if you delete some icon file A.ico in Windows and then rename another icon file B.ico to A.ico, the B.ico file's actual icon will change to A's. Anyway, I don't the name of the icon file is the issue.
Now, in code, if I use the same strategy and set one of my form's icons, it works correctly and the form displays my latest icon, while my notify icon still shows the old (and now nonexistent, except in Visual Studio la la land) icon.
So, I have:
...
if(firstState){
notifyIcon.Icon = Resources.IconA03312014;
optionsForm.Icon = Resources.IconA03312014;
}
else{
notifyIcon.Icon = Resources.IconB03312014;
optionsForm.Icon = Resources.IconB03312014;
}
firstState = !firstState;
...
There are no errors and both the notifyIcon and optionsForm's changes, but the notify icon displays my OLD icon that no longer exists anywhere (except somewhere/somehow in VS). The form's icon changes to my updated/latest icon.
If I copy my app's .exe file to another computer and run it, it too displays the old icons for the notify icon, so the old icons are somehow still embedded in my exe generated by Visual Studio. If I just directly load the .ico file, instead of referencing my project resources, the new icons ARE shown. This have to be some sort of strange Resources caching issue in Visual Studio?
Can anyone please help me with this issue? I just don't understand how my old icons are still existing somewhere, and how Visual Studio somehow knows how to switch them! That's right, the above icon swapout works perfectly for the form. But for the notifyIcon, the icon does switch from "A" to "B", but it uses the old A icon and the old B icon--icons that do not exist anywhere anymore!
I hope I have explained my issue. I greatly appreciate any help that anyone can provide.
I had this same problem a few months ago and it drove me crazy for a couple of hours. I was so focused on clearing on the icon cache and thinking that it was just some sort of caching issue that it didn't immediately occur to me what the real problem was.
The answer, for me at least: Even though you have a 16x16 version of your image in your .ico file, Visual Studio will instead use the 32x32 image and scale it down to 16x16, causing it to look distorted. I say VS did it because when I ran the executable on other machines (different Windows OS's), I saw the same behavior so it wasn't a Windows 8 issue, for me. (It might very well be a Windows issue in general though, I don't know. I did not take the time to verify what was actually inside of the generated .exe--did it contain MY 16x16 version, or 16x16 version generated by scaling down my 32px version? That would have confirmed it, I guess...)
My "aha" moment came when I added a few rows of red pixels to each size of my icon image, in a different section of my icon. So I put the red rows in my 16x16 at the bottom. My 32x32 had the red rows in the center, etc. So then I added this .ico to my project and started the project up and BAM, there was a distorted version of my 32x32 icon being used in the system tray as my notify icon. There was no doubt about it.
If you notice that your notify icon (at 16x16) looks more distorted than you would expect, you might use a similar strategy to see if this same automatic scaling is happening. When I figured this out, my quick solution was to add a .ico to my project that contained ONLY the 16x16 version of my icon image. I then use that resource image only for my notify icon. Obviously, if you did this (have a 16x16 only image) for forms, for example, you would see a very distorted icon in your taskbar, Alt-Tab list, etc., because Windows has no choice in that situation but to create the different icon image sizes by scaling your 16x16 because that's all that you supplied. Anyway, in my particular case, as I believe is yours as well, there was no issue using the .ico for forms--they show the actual embedded 16x16 version of the image and there is no "automatic downsizing" of the 32px version.
That's all I know. I did not spend anymore time on this issue because I had to move on. I hope this helps someone avoid some icon frustration. Why, oh why, VS would you do this to us!?
i had the same problem with a splash screen.
some how it did not change after replacing the picture.
what i did is i remove the images then save the form.
run the app and there was no image.
then i replaced them and the problem was fixed for me.
so maybe you can try the same with you're icons.
hope it will fix you're problem .
Open the file Resources.resx of your project with the editor. There you have to change name="Icon1" into name="YourIconName".

Incorrect icon size when imported to exe

EDIT: Solved, (at least for the explorer) the problem was it keeps the old thumbs.db.
I have a png icon and I've created a 128px, 96px, 64px, 32px, 16px icon using several tools. But the result is always the same.. when I compile the exe using that icon and resize to max icon size, it stays to something like 32-48px. Anyone got the same issue? Also when I put the executable on RocketDock, it also gets small icon. The executable has all icons, I checked it with Resource Hacker. It's a strange issue, I just wanted to make my app with big icon so it can be used in dock applications and on users that use bigger icon sizes.
Here's an example of what I'm talking about. The Visual Studio icon is there just for test.
And also a RocketDock screenshot containing a shortcut to the icon and to the executable:
I've used Axialis Icon Workshop successfully before, and it's even recommended in this MSDN article. Not free but the trial version should be enough for one-off shots. I'm not perfectly sure it will solve your problem but it should.

What could be causing design view to be so slow?

With small projects, I can switch to design view almost instantly (< 1 sec).
I have a large project that takes about 60 seconds to open a control or form in design view - for the first time only. After this 60 second delay, I can open any control in the project in design view almost instantly - until I recompile the project.
If the exe built by this project is referenced in another (small) project, the small project instantly becomes as sluggish as the large project. Similarly, if I add all the files from the large project to the small project individually, the small project becomes as sluggish.
The large project references a large Managed C++ project, but if I add the same reference (and call a function from the reference to make sure it is loaded) to the small project, the small project is still fast.
My large project uses SandDock. If my small project uses SandDock, it's still fast.
My large project has about 60 user controls that appear in the toolbox. If I add 60 user controls to the small project, the small project is still fast.
If I make the user controls hidden from the toolbox with [System.ComponentModel.ToolboxItem(false)], the large project is still slow.
The problem occurs in both vs2005 and vs2008.
What could be making the large project so slow to open design view for the first time? Some other reference? The large number of controls? The large number of classes? Some other cause?
One thing I've noticed (though possibly a red herring) is that the ProjectAssemblies folder (C:\Documents and Settings\tim.gradwell\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies) is huge (> 1GB) and most of the folders in here have a copy of my Managed C++ dll! These folders appear to get recreated every time the design view is re-opened (after a recompile). Could this have anything to do with the slowdown?
Further Info:
A toolstrip in the user control or form makes the form take 60 seconds to load. Removing the toolstrip (but still having several other different controls on the form) makes the switch to design view instant.
That's not the whole story though... A toolstrip in a brand new project doesn't cause massive slowdown - so there must be something in my big project which is affecting toolstrips. Also, certain other forms/controls that don't have toolstrips on them are still taking 60 secs to display the design view, so whatever it is that is affecting toolstrips is also affecting other controls too. I'll keep trying to nail down precisely which controls and maybe even what it is that's causing it!
Even though you have marked the classes to not appear in the Toolbox, Visual Studio still needs to scan all of your open projects to discover that. To speed things up, you need to turn off the setting to automatically populate the Toolbox. It can get a bit annoying if you do lots of work with the toolbox, but it will speed up things a lot.
The setting is in Tools -> Options -> Windows Forms Designer, set "AutoToolboxPopulate" to false.
The first answer: "The setting is in Tools -> Options -> Windows Forms Designer, set "AutoToolboxPopulate" to false" worked for me. The designer used to hang for at least a minute when trying to get focus on a control on a form when first looking at a form in design view. Now, it takes only a few seconds. (I didn't have enough reputation points to directly comment on that answer)
The same similar thing is happening with my 2005 in additon to that the devenv.exe hangs randomly
and even after "building" sometimes the custom controls tend to corrupt the main form
have you recently virus scanned and defragged?
I had this problem on a Win CE 6.0 project in Visual Studio 2005. The project uses System.Data.SQLite.dll v1.0.65.0. Each time I opened or recompiled the project, and then tried to open a form with a grid for design, there would be at least a 12-minute delay. Turns out it was generating 770-odd folders under "My Documents\Local Settings\Application Data\Microsoft\Visual Studio\8.0\Project Assemblies", most of which had a copy of just the SQLite dll.
The issue appears to be that I had referenced this DLL in the project from a "sibling" folder to my project. As an example:
Project folder: "...Projects\ThisAndThat\projectFolder"
DLL folder: "...Projects\ThisAndThat\projectFolderBin"
There may be other folder relationships that manifest this problem, but I did not investigate.
I moved the DLL into the "Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE" folder and the problem went away. I have a form with a tab control containing two tabs. Each tab contains a datagrid control. This form now loads almost instantly in the designer.
If anyone knows of a better solution, or what setting or behavior of VS2005 causes this issue, please add a comment.

Categories

Resources