Bob Goblin
Bob Goblin

Reputation: 1259

Text Box Height & Width

How can do you convert Microsoft Access Height & Width to a C# WinForm Height & Width? For example, I want Width 5.1667" & Height 1.667" (access) to a C# Windows Form Text Box. But if I attempt to input those figures into a C# Windows Form Height/Width property they are 1st invalid, so if I change the width to 5 it is considerably to small to enter data into...

What is the conversion method to convert that access text box size to a C# windows form size?

Upvotes: 2

Views: 527

Answers (1)

imjustaboy
imjustaboy

Reputation: 346

float accesswidth = 5.1667f;
float accessheight = 1.667f;
Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
float csharpwidth = accesswidth * graphics.DpiX;
float csharpheight = accessheight * graphics.DpiY;
MessageBox.Show(string.Format("width: {0}, height: {1}", 
                               csharpwidth.ToString(),
                               csharpheight.ToString()));

Upvotes: 3

Related Questions