How to properly align label to text box if DPI is changing? - c#

I have enabled these recommended settings in my config file:
<add key="DpiAware" value="true" />
<add key="DpiAwareness" value="PerMonitorV2" />
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
and also in the main function:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Everything is top and left anchored, this is how it looks on a 100% scaled display:
When I move the window to a 150 or 175% scaled display:
As you can see, labels are offset downwards, a few pixels.
The container's AutoScaleMode is set to DPI.
How can I preserve the alignment?

Related

Maui-blazor gradient splash screen

Is it possible to set a gradient splash screen?
In example
<MauiSplashScreen Include="Resources\Images\splashscreen.svg" Color="#512BD4" />
i want the background to be a gradient and have a word on it
Tried:
<MauiSplashScreen Include="Resources\gradientWithWord.svg" /> i tried set image, but size is set incorrect
Try to set BaseSize on MauiSplashScreen .
The value of the BaseSize attribute represents the baseline density of the splash screen, and is effectively the 1.0 scale factor for the splash screen from which all other density sizes are derived.
If we don't specify a BaseSize for a bitmap-based splash screen, the image isn't resized.
If we don't specify a BaseSize value for a vector-based splash screen, the dimensions specified in the SVG are assumed to be the base size.
Try
<MauiSplashScreen Include="Resources\Images\splashscreen.svg" BaseSize="128,128" />

Zoom in and crop using ImageProcessor.Web

Using ImageProcessor.Web (http://imageprocessor.org/imageprocessor-web/imageprocessingmodule/resize/) resize module, I'm able to get the image cropped to a defined size, like:
<img src="~/Content/img/fiji-01.jpg?width=500&height=500&mode=crop&center=0.1,0.1"/>
But how do I zoom in the picture twice the size and the crop?
Tried something like:
<img src="~/Content/img/fiji-01.jpg?mode=crop&center=0.9,0.9&heightratio=3&widthratio=3&height=500" />
It didn't help.
I had to set up Umbraco and use GetCroppedUrl method to see how it works. It happens that we use the crop module followed by resize module, like:
<img src="~/Content/img/fiji-01.jpg?crop=0.23159636062861869,0.061207609594706371,0.023986765922249794,0.19437551695616212&cropmode=percentage&width=500&height=500" />
or
<img src="~/Content/img/fiji-01.jpg?crop=50,50,200,200&width=500&height=500" />

Have a WPF Application ignore DPI settings

I have a wpf application that is designed for a 1900x1200 resolution but some of our users have used the windows display settings to resize everything by 125%-150%, is there a way to have an application ignore those settings and still display normally?
I have seen something called SetProcessDPIAware here, but havent had any luck with it.
Here is a screen shot of the application with the display scaling turned up to 150%
As you can see the application is way too small and there is no way to get it to be correctly sized.
Dpi awareness will not help in this case. It will only change CompositionTarget.TransformToDevice matrix, but controls sizes will not change.
I use view box to scale all content. All sizes in my app are designed for Surface Pro 3 portrait:
<Window>
<Viewbox Stretch="Uniform">
<Grid Width="1440" Height="2160">
<!-- ... -->
</Grid>
</Viewbox>
</Window>
You can calculate view box size basing on screen DPI. See this answer: https://stackoverflow.com/a/12414433/991267
New way to ignore dpi is:
Right click on your project
Add > New item
Find "Application Manifest File (Windows Only)
Uncomment at line 55, or find dpiAware
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>

Adjust RichTextBox font size under High DPI setting

My C# application includes grids with both simple text boxes and richtext boxes. Often the richtext boxes contain rich text copied and pasted from elsewhere, and often the rtf markup includes hardcoded font size (\fsXX, XX in half points). In most cases the rich text font size is the same or close to the simple text font size.
When the DPI scaling is set to anything other than the default 96 the rich text is distorted as follows:
a) When the application is NOT set to be DPI aware the richtext is shown smaller than the simple text and is blurry.
b) When the application is set to be DPI aware the rich text is larger than the simple text.
Is there a means to allow or force the richtext to scale with the simple text, short of editing the markup directly?
Try to set its property WordWrap to true.
One thing that might solve the problem is to set the RichTextBox on a form and set the AutoScaleMode property of the form to None (AutoScaleMode Enumeration documentation)
<script type="text/javascript">
tinyMCE.init({
mode: "textareas",
theme: "advanced",
plugins: "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: false,
template_external_list_url: "js/template_list.js",
external_link_list_url: "js/link_list.js",
external_image_list_url: "js/image_list.js",
media_external_list_url: "js/media_list.js"
});
</script>
<td class="textboxmain" style="height:300px; "><asp:TextBox id="textbox1" TextMode="MultiLine" Height="100%" runat="server" placeholder="test............"></asp:TextBox></td>
Maybe you can use a WPF form, so you don't have to worry about de DPI of different screens
Please try the following, it is supported only in .NET Framework 4.5.2 onwards. Microsoft has covered a few more controls for HighDpiAutoresizing.
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

Is there any way to change the position of ValueLabel in .Net Chart?

I want to change position of ValueLabel of my chart. What is the solution?
Also can I change size of that?
Did you try setting the LabelStyle which is a Custom property. here you can specify the positioning within the predefined ones like
Top, Bottom, Right, Left, TopLeft, TopRight, BottomLeft, BottomRight,
Center
I think I am too late, but as I had the same problem and found a solution, here it is:
yourChart.Series["yourSeries"]["LabelStyle"] = "Right";
This changes the position of the value label, NOT the axis label!
You can set the position by this way :
<Points>
<asp:DataPoint AxisLabel="1" YValues="14" />
<asp:DataPoint AxisLabel="2" YValues="11" />
<asp:DataPoint AxisLabel="3" YValues="16" />
<asp:DataPoint AxisLabel="4" YValues="4" />
<asp:DataPoint AxisLabel="5" YValues="3" />
</Points>

Categories

Resources