I got "LogInform" form. which has some labels, two text boxes (username and password). and a button "log in". size of form is (1149, 847).
When a user clicks on the button I have a SQL function that checks if the user exists in the database.
//log in to user
private void bunifuThinButton21_Click(object sender, EventArgs e)
{
if(ConsoleApp2.UsersDB.userExists(this.userName.Text,this.passWord.Text))
{
this.Hide();
}
else
{
bunifuThinButton22.Visible = false;
wrongUser.Visible = true;
timer2.Enabled = true;
}
}
and the SQL function (userExists) :
public static bool userExists(string userName,string passWord)
{
DataTable d1;
string com = "SELECT * FROM users where user_name='" + userName + "'AND user_password='"+passWord+"'";
d1 = oledbhelper.GetTable(com);
if (d1.Rows.Count == 0)
{
return false;
}
return true;
}
After the click everything goes like it should except for one thing - The window gets smaller by itself, there is no code that makes the window smaller after the click. I don't understand why it does it.
For those who don't understand what I mean, I made 20 sec video(where I start the form and put in some incorrect names and passwords and then press the button): youtube vid
I tried to set the "MinumumSize" with the regular size numbers, I tried to set "AutoSize" to false, I tried to set the Size of the window after it gets smaller(logInForm.size = new size(x,y)), I tried every possible way! I cant understand why it does it ); thanks for the help, hope I explained well enough..
Form size changes when you have high-DPI monitor with layout scaling enabled in Windows display settings. Winforms DPI autoscaling gets reset when your application loads any WPF-targeted DLL into memory (check Visual Studio output console at the time when it happens). For example, when PresentationCore.dll or PresentationFramework.dll are loaded, the scaling gets reset.
You can create app.manifest file overriding dpiAwareness setting:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
</windowsSettings>
</application>
...but this won't play together with ClickOnce manifest:
Installing ClickOnce published applications is not possible if there is a tag in the manifest file about the dpi-awareness. This is not something that ClickOnce explicitly supports. So you may need to exclude the DPI-aware part for ClickOnce deployment.
Solution is to add DisableDpiAwareness attribute to your Properties/AssemblyInfo.cs file:
// Disable Dpi awareness in the application assembly.
// Add reference to WindowsBase.dll
[assembly: System.Windows.Media.DisableDpiAwareness]
Related
I have an old legacy system that uses Winforms and is published with the built in One click,
I look after 3 different installs and each one has its own database it connects to, so its been set up that when a different system is click, it check isCompany1 and will set the Favicon accordingly
so when depoyment is done in the application window the Icon and Manifest is set to the correct ICO, when installed the .exe icon will be what is set there,
However i am trying to bring these all inline as when we debug a drop asks which database we would like to connect to, and depending on that it will set things up differently.
When running in VS the icons in the taskbar will change accoring to the dynamic Favicon however when its depolyed with this new selection it wont change, (it will change once on first load, then wont again)
The issue is some users need access to the different instances so would like different icons at the bottom, but its not changing the task menu, but everything else such as ALT-TAB and the control panel icon is changing,
all forms link into a baseform and call this :
if (App.IsCompany1)
{
this.Icon = new Icon("Resources\\Company1.ico");
}
else if (App.Company2)
{
this.Icon = new Icon("Resources\\Company2.ico");
}
else if (App.Company3)
{
this.Icon = new Icon("Resources\\Company3.ico");
}
AS i said this will change everything but not the Taskbar, but will from VS debugging,
I have made sure the .ico has all sizes, by writing their sizes on each one, and they display correctly the Taskbar and ALT-TAB both use 32x32
If it's any consolation, I couldn't reproduce your complaint.
I put 3 icons in resources, a single button on a form, this code:
private int iconum = 0;
private Icon[] icons = new[] { Properties.Resources.icon1, Properties.Resources.icon2, Properties.Resources.icon3 };
private void button1_Click(object sender, EventArgs e)
{
this.Icon = icons[iconum++ % icons.Length];
}
And it cycled through the icons in the main form title bar and the windows task bar over and over on every button click (made sure to run a release built exe too, not a debug start):
Note: the thing in the top right is my taskbar
Setting VisualStyles.VisualStyleState.NonClientAreaEnabled in code shows a completely different dialog for OpenFileDialog call than when done without a VisualStyleState. The drop down for "View Menu" shows a vertical bar without text and the left browser pane is gone.
Image showing problem with Visual Style State set
In our application we need to set Styles as we have developed custom ones.
Issue reproducible on Windows 10 Build 1709, .Net 4.6.1 and default C# forms application. Also reproduced on Windows 10 build 1809. Works fine with all earlier versions of Windows.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.NonClientAreaEnabled;
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.CheckFileExists = true;
fileDialog.Filter = " (*.sql)|*.sql";
fileDialog.ShowDialog();
}
}
Without VisualStyleState set, the OpenFileDialog shows a completely different UI, with browser pane on the left side and all drop downs work as expected.
Image showing default behaviour of OpenFileDialog
Any pointers to fix this issue would be helpful.
In one situation a dialog is rendered as an old style dialog and the other one as so-called “Vista-style” dialog:
old style
Vistay style
Here's the code the drives this decision:
https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/FileDialog.cs,986
A type of a dialog depends on whether VisualStyleState.ClientAreaEnabled is set or not. Because you set the style to VisualStyleState.NonClientAreaEnabled the app falls back to the old-style.
There is AutoUpgradeEnabled property that allow rendering the dialog as Vista-style, you could try setting it to true and see if it helps.
Universal app does not allow to remove or disable the close button it seems. We can hide it by going full screen. But when moving cursor over it, brings title bar back. Is there any way to remove the close button?
Reason : I am working on screen time. After allowed time gets over, I want to block the screen. I should remove close button so that user cant get over my app.
Edit : Removing close button wont help completely. It is a part of work. I am just asking how to remove it.
In Windows 10 version 1703 (build 10.0.15063) and beyond, you can prevent the app from closing, using the SystemNavigationManagerPreview class.
Add this to your app manifest:
<Capabilities>
<rescap:Capability Name="confirmAppClose" />
</Capabilities
You need to have the rescap namespace at the Package element:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
In the constructor of your main form, add:
var sysNavMgr = SystemNavigationManagerPreview.GetForCurrentView();
sysNavMgr.CloseRequested += OnCloseRequested;
OnCloseRequested can be implemented as follows:
private void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var deferral = e.GetDeferral();
e.Handled = true;
deferral.Complete();
}
With current released API, we are able to customize the color of these three buttons in title bar. But there is no property or method could be used to disable or remove these buttons.
In UWP, we can use ApplicationView.TitleBar | titleBar property to get the title bar like following:
ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
This property's type is ApplicationViewTitleBar. It only has several properties that can customize the button's color like:
titleBar.ButtonBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White;
Using these properties may make the close button invisible like:
However this won't actually hide these buttons. Users can still minimize or maximize the app and when the pointer is over the top right corner, they will still see the close button.
From Windows 8.1, if we want users to use only an application and do nothing else including closing the application, we can use Kiosk Mode. For more info, please see Enable Kiosk Mode in Windows 8.1 and Set up a kiosk on Windows 10 Pro, Enterprise, or Education. However this won't meet your requirement as you want to block the screen after allowed time gets over.
So UWP may not be the best choice for your requirement. You may try to implement it with classic desktop apps.
in App.Xaml.cs add this code :
// Collapse Title bar
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(null);
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();
C++ Version
// COLLAPSE THE TITLE BAR
Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
Window::Current->SetTitleBar(nullptr);
Windows::UI::ViewManagement::ApplicationView^ view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
view->TryEnterFullScreenMode();
I am currently writing a running tracker, and I want it to be possible for the user to have my application running in the background.
Everything is fine when running it in the background, but whenever I re-open the app, it puts me back at the main menu.
In the end, I want access to the RootFrame.BackStack, so that the user can pick up where they left off.
I tried the following code in my App.xaml.cs but it threw a "InvalidOperationException" at the attempt to access RootFrame.BackStack.GetEnumerator().Current.
Note: I checked, and all values before Current are non-null.
private void Application_Activated(object sender, ActivatedEventArgs e)
{
JournalEntry j;
if (RootFrame.BackStack.GetEnumerator().Current != null)
j = RootFrame.BackStack.GetEnumerator().Current;
RunningInBackground = false;
}
What you're looking for is called Fast App Resume:
Windows Phone 8 introduces the ability for apps to request that user
actions that would typically relaunch the app, such as tapping the
app’s Start Tile, instead resume the suspended instance of the
suspended app instance, if one exists. This feature is called Fast
Resume.
To enable Fast Resume for your app, add the ActivationPolicy attribute to the DefaultTask element in WMAppManifest.xml and set the value to “Resume”.
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"/>
try this sample link. I hope this is what you are looking for. http://code.msdn.microsoft.com/wpapps/Fast-app-resume-backstack-f16baaa6
I am developing an application called WeatherBar. Its main functionality is based on its interaction with the Windows 7 taskbar — it changes the icon depending on the weather conditions in a specific location.
The icons I am using in the application are all stored in a compiled native resource file (.res) — I am using it instead of the embedded resource manifest for icons only. By default, I modify the Icon property of the main form to change the icons accordingly and it works fine, as long as the icon is not pinned to the taskbar. When it gets pinned, the icon in the taskbar automatically switches to the default one for the executable (with index 0 in the resource file).
After doing a little bit of research, I figured that a way to change the icon would be changing the shortcut icon (as all pinned applications are actually shortcuts stored in the user folder). But it didn't work.
I assume that I need to change the icon for the executable, and therefore use UpdateResource, but I am not entirely sure about this. My executable is not digitally signed, so it shouldn't be an issue modifying it.
What would be the way to solve this issue?
If you want to do this programatically, I would start by looking at the Portable Executable file format (Wikipedia entry). The resources section (.rsrc, see section 6.9) should contain the icon. Using this information, you can write a tool to modify the icon.
If you just want to quickly change an icon in an existing file, you might be able to hack it up in the Visual Studio resource editor. I tested this with a file by deleting the old icon and adding a new one. The .exe icon changed in Explorer to the new icon, and the new icon appeared on the Start menu when I dragged it there.
-- Edit --
Yes, I agree that using UpdateResource is a good approach. Here is an example I found of using C++ functions to do so, and a P/Invoke signature for UpdateResource and FindResource.
private void button1_Click(object sender, EventArgs e)
{
String path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
String name = "test";
Shell32.Shell shl = new Shell32.ShellClass();
// Optional code to create the shortcut
System.IO.StreamWriter sw = new System.IO.StreamWriter(path + #"\" + name + ".lnk", false);
sw.Close();
// End optional code
Shell32.Folder dir = shl.NameSpace(path);
Shell32.FolderItem itm = dir.Items().Item(name + ".lnk");
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
// Optional code to create the shortcut
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System)
+ #"\notepad.exe";
lnk.Description = "nobugz was here";
lnk.Arguments = #"c:\sample.txt";
lnk.WorkingDirectory = #"c:\";
// End optional code
lnk.SetIconLocation(Environment.GetFolderPath(Environment.SpecialFolder.System)
+ "cmd.exe", 1);
lnk.Save(null);
}
This was taken from http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9e23a82c-8bed-4b96-8b9a-4c2b6136a622/
It may help.
I decided to implement a workaround - the icon will change in the thumbnail for the window (it is possible in Windows 7). If the icon is unpinned, the user can see the icon changing. In case it is pinned, the thumbnail will change according to the current weather conditions.
Seems to me like the structure of pinned icons (being a shortcut, in fact) doesn't allow dynamic icon change. If I am wrong, I am open for comments and ideas on this.