Lots of people won't download attachments. It's generally best to post the code wrapped in CODE tags (the # button), though, in this case, it may be that there are images that may seem relevant.
Lots of people won't download attachments. It's generally best to post the code wrapped in CODE tags (the # button), though, in this case, it may be that there are images that may seem relevant.
I would recommend just adding code to draw a rectangle to the Form's paint event rather than depend on the shape controls, which were added kind of as an afterthought and aren't that reliable and if someone is running the community version of VS2015, I think it is a separate download to get the shape control libraries. I think even for the free version of VS 2010 it wasn't installed as part of the basic install.
Code:
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawRectangle(Pens.Black, 20, 20, 800, 500)
End Sub
I would recommend just adding code to draw a rectangle to the Form's paint event rather than depend on the shape controls, which were added kind of as an afterthought and aren't that reliable and if someone is running the community version of VS2015, I think it is a separate download to get the shape control libraries. I think even for the free version of VS 2010 it wasn't installed as part of the basic install.
Code:
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawRectangle(Pens.Black, 20, 20, 800, 500)
End Sub
I assume you changed the numbers to be appropriate to the size rectangle you wanted, and the last two parameters are width and height of the rectangle, not the lower right coordinates of the rectangle.
There could be some run-time dpi based scaling going on. If you make the form smaller so that you can run it and see the form and compare it to the size of the form in the IDE (Integrated Design Environment), does the form and controls on the form appear the same as they are in the IDE or are they a different size.
Also, try this test which works fine on the machine I'm currently on.
I'll add a button to the form at a certain spot and size, then change the rectangle code to draw the rectangle around it with a 10 pixel border.
On this machine I see a flat button with a blue border surrounded by a black rectangle evenly space around the perimeter.
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim b As New Button
b.SetBounds(100, 100, 100, 50)
Me.Controls.Add(b)
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawRectangle(Pens.Black, 90, 90, 120, 70)
End Sub
That indicates to me that the button size and the drawing coordinates are using the same scale on this machine.
Last edited by passel; Sep 22nd, 2017 at 11:18 AM.
I assume you changed the numbers to be appropriate to the size rectangle you wanted, and the last two parameters are width and height of the rectangle, not the lower right coordinates of the rectangle.
There could be some run-time dpi based scaling going on. If you make the form smaller so that you can run it and see the form and compare it to the size of the form in the IDE (Integrated Design Environment), does the form and controls on the form appear the same as they are in the IDE or are they a different size.
Also, try this test which works fine on the machine I'm currently on.
I'll add a button to the form at a certain spot and size, then change the rectangle code to draw the rectangle around it with a 10 pixel border.
On this machine I see a flat button with a blue border surrounded by a black rectangle evenly space around the perimeter.
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim b As New Button
b.SetBounds(100, 100, 100, 50)
Me.Controls.Add(b)
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawRectangle(Pens.Black, 90, 90, 120, 70)
End Sub
That indicates to me that the button size and the drawing coordinates are using the same scale on this machine.
aha - you have pointed me in the right direction when you say dpi scaling. :^)
When I checked the display settings there was a scaling of 125%
I removed the scaling and put it back to 100% and rebooted the PC
and viola it worked - thanks very much - hours down the suwannee river with that one :^)
so in this case how could you rectify it with code if there was a scaling?
The mointor is 4k - and the text is a wee bit small :^) hence the scaling
Fortunately I haven't had to deal with it yet so unfortunately I don't have remedies.
The one thing I do hear repeatedly is to learn to use WPF projects instead of WinForm projects since WPF is dpi aware and you won't have those issues.
If you're new to programming, then perhaps it is best to start doing WPF projects and go up that learning curve, rather than going up the winform curve and be biased toward it and have another transition to wpf later.
By the way, I'm well entrenched in the winform way and have very little wpf exposure so wouldn't be of any help in that arena.
Fortunately I haven't had to deal with it yet so unfortunately I don't have remedies.
The one thing I do hear repeatedly is to learn to use WPF projects instead of WinForm projects since WPF is dpi aware and you won't have those issues.
If you're new to programming, then perhaps it is best to start doing WPF projects and go up that learning curve, rather than going up the winform curve and be biased toward it and have another transition to wpf later.
By the way, I'm well entrenched in the winform way and have very little wpf exposure so wouldn't be of any help in that arena.
In terms of DPI scaling it is very, very hard to rectify the problems with Windows Forms and this is something people are increasingly encountering as monitors with higher resolutions are more common.
Windows Forms is a framework developed in the early 2000s based on GDI+, which is itself based on GDI which was developed in the 1980s for Windows 3.1. For almost all of its 30-year history, there were only 3 common monitor sizes and one "resolution", which really means "dot pitch". Microsoft has tried since 2003 to introduce an automatic scaling algorithm that handles different display sizes, but so far they've only managed to make it worse.
So in Windows Forms today, there are at least 2 different scaling algorithms that might be used based on your .NET version. THEN there are at least 4 different scaling algorithms Windows might apply IN ADDITION TO the .NET scaling algorithm, mostly based on which version of Windows you use. Getting it "right" if you want to support many resolutions generally means throwing away the designer and hand-writing your layouts using a device-independent unit instead of pixels.
Or you can forget Windows Forms exists and learn WPF instead. It was designed from 2006-2010 when MS saw this problem coming and it already uses device-independent units. Lots of people are fond of saying it's "harder to learn". It's more that it's "harder to explain, and unfamiliar". I've been doing projects for iOS, Android, and the web lately, and I guarantee you WPF is still an "easy" framework to learn at a basic level.
Personally, I prefer writing my GUI apps with NodeJS these days. HTML UI works on every platform. WPF works on Windows and nothing else.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.