Alignment Troubles with Panel1.Controls.Add(browser)

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Alignment Troubles with Panel1.Controls.Add(browser)

Postby vmars316 » Mon Oct 05, 2020 12:09 pm

Hello & Thanks;
Having Alignment Troubles with Panel1.Controls.Add(browser) .
And 3 controls in all .
When a webpage is displayed (skewed) about 50px below the top
and 20px to the right of where it should be .
How can I fix this ?
I have both a .vb & .cs version . Both have the same issue .
Below is Form1.vb followed by Form1.Design.vb .
Thanks for your Help...
Form1.vb

Code: Select all
Imports cef
Imports CefSharp
Imports CefSharp.WinForms
Imports System.Windows.Forms

Public Class Form1
    Private WithEvents browser As ChromiumWebBrowser
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim setting As New CefSettings
        '        setting.RemoteDebuggingPort = 8088
        CefSharp.Cef.Initialize(setting)
        browser = New ChromiumWebBrowser("https://www.google.com/") With {
                .Dock = DockStyle.Fill
                }
        Panel1.Controls.Add(browser)
        browser.Load(TextBox1.Text)

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        browser.Load(TextBox1.Text)
    End Sub

End Class



Form1.Design.vb

Code: Select all
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Button5 = New System.Windows.Forms.Button()
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(336, 14)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(210, 26)
        Me.TextBox1.TabIndex = 4
        Me.TextBox1.Text = "http://vmars.us/SafeBrowser/SafeBrowserHome.html"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(552, 14)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(75, 32)
        Me.Button5.TabIndex = 5
        Me.Button5.Text = "Button5"
        Me.Button5.UseVisualStyleBackColor = True
        '
        'Panel1
        '
        Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel1.Location = New System.Drawing.Point(9, 63)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(1201, 602)
        Me.Panel1.TabIndex = 7
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 20.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(1222, 677)
        Me.Controls.Add(Me.Button5)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents TextBox1 As TextBox
    Friend WithEvents Button5 As Button
    Friend WithEvents Panel1 As Panel
End Class


Image
vmars316
Techie
 
Posts: 18
Joined: Sat Sep 26, 2020 9:40 pm

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby magreenblatt » Mon Oct 05, 2020 12:22 pm

This is not a support channel for CefSharp. See Contact links at https://github.com/cefsharp/CefSharp.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby amaitland » Mon Oct 05, 2020 2:54 pm

You likely need to make your application DPI aware.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby vmars316 » Mon Oct 05, 2020 4:25 pm

Thanks ,
Yes , because of eyesight issue , I run with DPI at 150% .
Code: Select all
Class SurroundingClass
    Private [Public] As [Private]
    Private Sub EnableHighDPISupport()
End Class

Public Class Form1
    Private WithEvents browser As ChromiumWebBrowser
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub


Should I enable dpi or disable it .
I tried this: Private Public void EnableHighDPISupport()



But get these errors:

Severity Code Description Project File Line Suppression State
Error BC30026 'End Sub' expected. ChromeVB01 C:\Users\vmars\source\repos\ChromeVB01\Form1.vb 8 Active
Error BC30002 Type 'Private' is not defined. ChromeVB01 C:\Users\vmars\source\repos\ChromeVB01\Form1.vb 7 Active

How to proceed ? Thanks
vmars316
Techie
 
Posts: 18
Joined: Sat Sep 26, 2020 9:40 pm

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby amaitland » Mon Oct 05, 2020 4:48 pm

Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby vmars316 » Mon Oct 05, 2020 6:34 pm

Thanks;
I stuck recommended .xml into all CefSharp.WinForms.XML files .
That made an improvement , but still off :
Image

But I can't expect kids (KidsSafeBrowser) to adjust 'display settings' if needed .
If I can't do it programatically , is there a way to use some sort of
scripting or .bat , etc. ?

Thanks
vmars316
Techie
 
Posts: 18
Joined: Sat Sep 26, 2020 9:40 pm

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby vmars316 » Tue Oct 06, 2020 6:47 pm

I just noticed that when I click on a Link
up pops a new window & all is aligned ,
except that no GO button and no Address txt box .

Is that a clue or just a popup ?
Thanks
vmars316
Techie
 
Posts: 18
Joined: Sat Sep 26, 2020 9:40 pm

Re: Alignment Troubles with Panel1.Controls.Add(browser)

Postby vmars316 » Thu Oct 08, 2020 10:23 am

Turns out
when I add the following in App.config.

Code: Select all
   <System.Windows.Forms.ApplicationConfigurationSection>
     <add key="DpiAwareness" value="PerMonitorV2" />
   </System.Windows.Forms.ApplicationConfigurationSection>

Everything works as expected.
Thanks for your Help...
vmars316
Techie
 
Posts: 18
Joined: Sat Sep 26, 2020 9:40 pm


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 17 guests