|
hi all
how i get the dpi scale factor is selected.
thanks.
|
|
|
|
|
Where are you going to get it from?
|
|
|
|
|
|
var graphics = control.CreateGraphics())
int dpi_scale_val= graphics.DpiX;
but it always return 96
|
|
|
|
|
Le@rner wrote: but it always return 96 That is correct.
|
|
|
|
|
i have 4k laptop its by default resolution is 200%
|
|
|
|
|
If you want help with a programming question, you really need to provide proper details, rather than vague statements.
|
|
|
|
|
|
|
"200%" is not a resolution. It's a scaling factor used to enlarge text when displayed.
The display dpi is still 96.
One has nothing to do with the other.
|
|
|
|
|
yes i want this scaling factor in c#
|
|
|
|
|
|
Name of the school/uni?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
DPI scaling is not that simple.
Here's how I do it for WinForms apps:
First, your app needs to be DPI-aware. You set that by the manifest. You also set that with with the AutoScaleDimensions and AutoScaleMode properties on each form.
Second, if you're designing forms from within Visual Studio, you need to do it on a system that is using 100% as the scaling factor for the display. If you don't do this, step 3 doesn't work.
Third, you can now use
scaleFrom96 = this.DeviceDpi / 96.0 to calculate a multiplication factor for resizing those things manually that WinForms will not do for you. Be warned, it is very hit and miss what things will be scaled for you automatically and what things will not. Lots of testing required.
OR you punt it all and design on a system that matches the system the app will be running on.
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
Judy,
Great answer, I hope to see you answering more C# related questions in the future.
The Windows API equivalent to what you are doing there would be calling the GetDpiForMonitor function[^] and obtaining the MDT_EFFECTIVE_DPI[^] value and dividing by the system default. Of course the operating system hides dpi/scaling values from threads unless it's DPI aware[^]. So the caller needs to set thread DPI awareness before performing the calculation.
I'd like to add that GetScaleFactorForMonitor[^] may return incorrect values. The manual calculation is preferred.
I'd also like to add that the process doesn't necessarily need to be DPI aware. Beginning with Win10 1607 you can create a DPI aware thread to get those values by using the SetThreadDpiAwarenessContext function[^].
Hope to see you answering more often!
Best Wishes,
-David Delaune
|
|
|
|
|
I saved my password in CAPS includes but if i enter in small letters its also logged in how to change it?
private void button14_Click(object sender, EventArgs e)
{
if (textBox9.Text != "" && textBox10.Text != "")
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
string id = textBox9.Text;
string password = textBox10.Text;
textBox9.Text = "";
textBox10.Text = "";
string query = "select count(*) from login where userid=@userid and password=@password";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@userid", id);
cmd.Parameters.AddWithValue("@password", password);
cmd.Connection = cnn;
cnn.Open();
cmd.ExecuteNonQuery();
int result = Convert.ToInt32(cmd.ExecuteScalar());
DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes && result > 0)
{
MessageBox.Show("Login Successfully");
cnn.Close();
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
}
else
{
MessageBox.Show("Login Failed");
}
}
}
else
{
MessageBox.Show("Please Enter Correct Login details");
}
}
}
|
|
|
|
|
There is no point in answering this: you haven't listened to a thing we said in reply to any of your other questions: you are just copy'n'pasting junk code without thinking about it at all and relying on others to fix it for you.
You aren't learning anything from us; you aren't even trying. All you are doing is becoming a Help Vampire who wastes our time.
Go away, get a book, and start learning how to code properly: copy'n'paste'n'hope is not a valid development method.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok provide solution and article link pls
|
|
|
|
|
Again, you are ignoring everything we tell you ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You've already been given those links, and you're STILL ignoring them.
|
|
|
|
|
Please provide solution or idea
|
|
|
|
|
All this time and you still don't get it.
You've already been given all the links to read to figure this out. You just refuse to do the work yourself.
|
|
|
|
|
I have stored userid and password in mysql database, this query is showing login successfully for not stored data, so please correct it
string query = "select * from login where userid=@userid and password=@password";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@userid", id);
cmd.Parameters.AddWithValue("@password", password);
cmd.Connection = cnn;
cnn.Open();
cmd.ExecuteNonQuery();
DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation Message", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
MessageBox.Show("Login Successfully");
cnn.Close();
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
|
|
|
|
|
You're STILL begging other people to do your work for you.
Do you have any idea what ExecuteNoQuery does? No? READ THE DOCUMENTATION ON IT[^]! It returns a value you're not examining at all. You're actually throwing it away!
And why would you ask the user if they want to login AFTER they enter credentials you try to to check them against the data? That makes no sense.
Why would you put the code to close the database connection dependent on the result of a messagebox?
|
|
|
|
|
To add to what David has said, you are also putting yourself at quite considerable risk: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
The more I see of "your code" the more I think you aren't anywhere near ready for whatever it is you are trying to do ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|