Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning, following the advice of my last post, "https://www.codeproject.com/Questions/5376961/Translating-yield-return-to-VB" I updated the 2010 version to the 2015 version. Now I have all the forms, and there are hundreds of them, with an incorrect layout, i.e. the height of the top bar and the edges of the forms are much wider. Is there a method to solve it? I searched online but didn't find anything. I took some screenshots, but I don't know how to add them, it won't let me. Thank you all

What I have tried:

I haven't tried anything, it's not about the code but the interface. Thank you
Posted
Updated 10-Feb-24 4:36am
v3
Comments
10071962 10-Feb-24 8:16am    
Thanks, I've read everything but I don't think it's a problem with "AutoScaleDimensions", or with "AutoScaleMode.Dpi", but I think it's a different management of the form by the compiler. The problem is not only in execution but above all during the creation of the form in a visual way. Even if you add an empty form, the size of the border and the height of the title bar of the form is 10 pixels greater than in vs2010 and this affects the imported forms which should be left pixel by pixel as they were. Or am I the one who doesn't understand...
10071962 10-Feb-24 8:35am    
I forgot a detail to be more precise, the biggest difference is especially noticeable by setting FormBorderStyle.FixedToolWindow, the size is completely different.
M-Badger 10-Feb-24 12:29pm    
Good to see you moving away from 2010 to a newer version that includes Yield in VB :-)
Good luck!

1 solution

I may be mistaken but I suspect that the difference is that vb 2015 programs will be consistent with the Windows 10 styling, including the larger title bar. Whereas vb 2010 programs will be accessing older libraries and their styling is therefore consistent with Windows prior to Win 10.

You could therefore hide the title bar and replace it with a user control that has the height that you need. If you also nee the functionality of the title bar (Minimise, Maximise, Move the window, Exit etc. then you'd have to add that functionality back in with your own controls.

1. Remove the window title bar by setting the `FormBorderStyle` property of your form to `None`. This will remove the title bar along with the minimize, maximize, and close buttons.

2. Create custom buttons and use the appropriate methods to minimize, maximize, and close the form. To move the window, you can handle the `MouseDown`, `MouseMove`, and `MouseUp` events.

3. This is a very low quality example just to show how it works, you'd need to do it more seriously if you go down this route. For instance, you might want to add checks to ensure the form doesn't move off-screen. Also, consider the user experience when designing your custom title bar, as it will not behave exactly like a standard title bar. For example, double-clicking to maximize will not work unless you implement it yourself.
VB.NET
Public Class Form1
    Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub

    Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub

    Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
        If drag Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub

    Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
        drag = False
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnMaximize_Click(sender As Object, e As EventArgs) Handles btnMaximize.Click
        If Me.WindowState = FormWindowState.Normal Then
            Me.WindowState = FormWindowState.Maximized
        Else
            Me.WindowState = FormWindowState.Normal
        End If
    End Sub

    Private Sub btnMinimize_Click(sender As Object, e As EventArgs) Handles btnMinimize.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub
End Class

4. `btnClose`, `btnMaximize`, and `btnMinimize` are your custom buttons for closing, maximizing, and minimizing the form, respectively. You'll need to add these buttons to your form and wire up the `Click` events.

5. The `Form1_MouseDown`, `Form1_MouseMove`, and `Form1_MouseUp` methods handle moving the form when the user clicks and drags the form. The `drag` variable is used to track whether the form should be moving.
 
Share this answer
 
Comments
10071962 11-Feb-24 8:52am    
I noticed that by importing the entire project from 2010 to 2015, the compiler adds 10 pixels in height and width, as you say for the Windows 10 style. The problem is that by doing so it modifies the entire layout added programmatically. Your suggestion would be fine for a few windows, but changing hundreds of them is equivalent to rewriting the project from scratch with net 4.5. Thank you for your suggestion.
M-Badger 11-Feb-24 9:00am    
It sounds like the changes it makes are therefore predictable even if they aren't as simple as 'change the top property of all controls by minus 10 pixels'. If you can predict them then you can reverse them with a simple piece of code to find all top properties and modify them appropriately.
10071962 11-Feb-24 9:13am    
The only solution I see is to import the project into vs2015, then create a routine that searches for all the properties involved in the layout and modifies the value. The only problem is that I don't trust the result (I don't remember all the changes made) and I should still check all the windows. This or rewrite everything from scratch. Thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900