visual studio grid snap to edge spacing - winforms

I'm designing a form in VS2008 and I want to snap controls to the left and right edges of the form but with more space than it gets now.
I tried changing the gridsize but that doesn't do it.
The form is for the compact framework so i'm designing for a smartphone I don't know if that makes a difference. I guess it ought to be the same setting.
Is there a setting somewhere that holds the space between the control and form edge?

The form's Padding property has a somewhat mysterious effect on the snap location. Setting Padding.Left to 1 makes it snap to X=4, 2 to 5 etc. No idea how well that reproduces but might be good enough for what you're trying to do. Directly editing the Location.X property would certainly work too.

Related

How to fix the order of items within a ToolStripContainer

I have a ToolStripContainer with a MenuStrip and a ToolStrip inside, both at the top. They're arranged as usual on Windows with the menu bar above the toolbar. Now, Windows Forms and DPI scaling support has always been a bit iffy. While everything looks fine at 100 %, I'm currently using 110 % DPI scaling and the menu bar and toolbar switch positions in the ToolStripContainer (I'd suspect it's the same with higher scaling factors, though):
My guess as to why this happens is that the designer places both controls at specific locations, even though they are arranged by the container, and with DPI scaling the ToolStripContainer gets locations for its children that would be consistent with placing the toolbar above the menu bar, as if someone dragged the bars around and reordered them (which is possible interactively, after all).
Short of replacing the MenuStrip with a MainMenu, is there a simple(ish) way of ensuring that regardless of DPI scaling the order of both remains consistent? I've got about 50 different windows to change in pretty much the same manner and would also rather avoid putting extra code into the codebehind file¹.
Things I've tried so far:
All changes in the designer have been applied at 100 % scale.
Change the z-order of the toolbar and menu bar in an attempt to control their order. This works with panels and docking, but doesn't apply to ToolStripContainer, apparently.
Docking the MenuStrip at the top. Doesn't work; the designer just removes Dock = None from the code and displays Top as the default value, but with scaling applied, it's back to Dock = None in the designer (and even without touching the Form in the designer, the result at runtime is the same).
¹ These are demo applications for a control library and the main point here is to keep the code clean and still providing a good experience out of the box. So a designer-only solution where the code is hidden away in already-awful code that no one reads would be preferable.
They are very frustrating components to work with. Because they can be dragged and moved it looks like the Location is the key, even though they behave a bit like they're docked. In OnLoad or OnShown have you simply tried resetting the desired location?
menuStrip.Location = new Point();
toolStrip.Location = new Point(0, toolStrip.Height);

Silverlight and ClearType: just won't do

I am desperately trying to improve the visuals of my Silverlight application, but it won't work.
No matter what I do, I always get grayscale antialiasing, while I would like to get the standard Windows 7 full-color ClearType antialiasing. If I zoom in, this is clearly visible.
I am currently doing it by setting the following properties:
TextOptions.TextHintingMode="Fixed"
TextOptions.TextRenderingMode="ClearType"
To check that they are applied, I tried to set the TextHintingMode to Animated, and it gets a lot worse. Same thing if I set TextRenderingMode to Aliased: I see that it changes too, so I am setting them in the right place. Unfortunately the final effect is ugly.
How can I turn ClearType on?? Using Silverlight 5.
Thanks!!

How do I remove the border of a WPF window in the Design view/tab?

I am trying to remove the border of my WPF window in the design view/tab in Visual Studio. Please don't mistake this as a request to create a border less WPF window. I did that and it is working fine. What bothers me is that even if you have set WindowStyle = None, ResizeMode = NoResize, the design view/tab still shows a border around your window in the preview.
Is there a way to remove said border and have a 1:1 preview of the border less window as in Windows Forms?
Every question I have found in regards to this only asks how to remove the border of the actual application. I would like to remove it in the preview.
Any help would be very much appreciated :)
here is a screenshot of my problem:
This cannot be done as this is just how Visual Studio renders a window in design view (I think the frame is probably there so that you can distinguish when you are editing a Window rather than a UserControl).
Rather than try and find a solution to this I would ask myself if this is something I need to be spending time figuring out - after all you say that your program works correctly when being run. I think your time will be better spent writing code for your program rather than trying to play with the design time environment.
Update: In response to you comment, consider that the window frame will be different on every users machine depending on their operating system version (XP vs. Win7) or the theme the user has installed.
My computer has XP installed so the side borders are a lot thinner than those shown in design time so any content will be smaller (but only my a few pixels - 4 in my case; does your user interface design really depend on 4 pixels?).
When using a technology such as WPF you should not be designing your UI to fit to exact pixel sizes; you should be designing with min / max values or using layout containers that adjust to the size of the window as set by the user. Any regions in your UI (E.G. sidebar and main content) should be expressed as a ratio or percentage of one another; instead of saying "The side bar is 150 pixels wide and the main content area is 350 pixels wide" you should be saying "The side bar takes up a third of the window width and the main content takes two thirds".
Although the question is very old and have already been answered (kind of), I just realized: if you set WindowStyle="None", your undesired border is gone.

Control snapping in Visual Studio 2010

I'm sort-of just nit picking here, but maybe there's a simple solution which will save me some time.
When I'm drawing my Winforms GUI in the designer, controls snap to certain points. I can align the baseline of the text of one control to that of another, I can align the left and/or top of one control to another, etc. This is all great.
What's great too, is that the controls snap to other controls spaced with their margins. This means that if I'm making a vertical array of TextBoxes, then I can have them equidistant in my GUI - it looks less messy.
However not everything snaps correctly, or at all. Say I have put in my TextBoxes and now I wish to reduce the width of my form so that there is no white space between the edges of the TextBoxes and the edge of the form. Additionally, I want the distance between the edge of the TextBoxes and the edge of the Form to be the same on the left as it is on the right. If I drag the right edge of the form to the left, towards the TextBoxes it will not snap. I'm left with either calculations to work out what the width should be, or a juggling act to gradually reduce the width until the TextBox is snapping to both the left of the right.
I'm not saying this process is particularly difficult or time consuming. It's just that if it were to snap, the whole process would be infinitely easier.
Is there a built-in option in VS2010, or perhaps an extension? Or maybe I'm just doing it wrong in the first place?
The snap lines in the designer work perfectly when moving or resizing any of the built-in controls. The only time that they don't work is when you are resizing the form itself.
I agree that it would be extremely convenient to have snap lines here, as well. I wish I knew of a way to enable this. But unfortunately, I don't believe that there is one.
The workarounds are either to calculate the proper size mathematically, or guess at resizing the form then check your work by dragging one of the controls (and using the snap lines that appear). I go through the same "juggling act" that you describe on an unfortunately regular basis.
Whenever a control needs to be positioned so that it "snaps" to a form edge I usually move (or resize) the controls to the correct size first, and then change the controls "Anchor" property of those controls to be anchored to the corresponding form edge (even if the form itself won't be allowed to resize).
That way whenever I resize the form, the controls position relative to that form remains the same, simply resizing or moving the control as required (depending on the Anchor property chosen).
I completely agree that the ability to "snap" the form to controls when resizing the form would be extremely useful, but its normally possible to work-around using the anchor property in this way - the times when its doesn't work (such as when a form consists entirely of a column of text-boxes is a fixed height), I'm afraid you need to resort to calculations, but I find that most of my dialogs are resizable.

WinForms Control position in Simplified Chinese

We have a WinForms application that includes controls such as picture boxes that are positioned on a form. The base application is in English.
We've translated this application to a number of different languages (French, Spanish, Danish, Greek, etc.) and most recently to Simplified Chinese. The translated application works perfectly on our operation systems (English).
One of our customers installed the application on their operation system, Windows XP in Simplified Chinese. The layout of our application is broken. Simply put, the elements are pushed to the bottom right by a factor that is proportional to the distance between the element and the top left corner. For example, an element at the top right corner in design view is pushed off screen to the right whereas the items at the bottom of the page are pushed downwards and to the right.
The application supports switching languages while in use. When the locale is en-US, there are no layout issues. When switching to Simplified Chinese, the issue appears, but only on the Simplified Chinese operating system. The screen resolution and DPI are the same.
Do you have any ideas? I'm sure it must be a simple configuration setting somewhere, but I have been unable to solve this issue.
The size of the system base font matters as well. Which is indeed something you can change on XP. This will invoke the form's auto-scaling logic, designed to ensure that the controls grow larger to fit the larger font size.
This is by design, controlled by the form's AutoScaleMode property. Don't change it, rescaling is important. Just make sure the form layout still looks good, use properties like Anchor and Dock, controls like TableLayoutPanel, FlowLayoutPanel. Or the Resize event for tricky ones.
Paste this into your form to test this logic without having to change system settings:
protected override void OnLoad(EventArgs e) {
this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints * 125 / 96);
}

Resources