Winforms искажаются с помощью CefsharpC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Winforms искажаются с помощью Cefsharp

Сообщение Anonymous »

У меня есть приложение Winforms в C#, которое работает нормально. Я пытаюсь интегрировать CEF с ним. Как только я инициализирую Cefsettings, все мои формы искажаются. Я новичок в Winforms и не могу понять, как решить эту проблему. Мне нужна помощь, чтобы решить эту проблему. Я прикрепляю код и изображение для лучшего понимания. Форма без формы CEF с CEF 0 искаженным
Это моя программа.

Код: Выделить всё

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using TICKET_GPT.GPT_FORMS;

namespace TICKET_GPT
{
internal static class Program
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string string_0, string string_1);

// Token: 0x060000FF RID: 255
[DllImport("kernel32.dll")]
internal static extern void ExitProcess(uint uint_0);

public static FRM_APP_LOADER frmLoader;

[DllImport("Shcore.dll")]
private static extern int SetProcessDpiAwareness(int awareness);

/// 
/// The main entry point for the application.
/// 
[STAThread]
static void Main()
{
try
{

SetProcessDpiAwareness(2); // 2 = Per Monitor DPI Aware
if (Environment.OSVersion.Version.Major >= 6)
{
SetProcessDpiAwareness(2);
}

int processCount = GetCurrentProcessCounts();
if (processCount > 1)
{
//MessageBox.Show("Supremo is Already running");
return;
}
Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

TICKET_GPT.GPT_BL.IRCTC.OPEARTIONS.CefSharpBrowserAutomation.InitCefSettings();

#region --- Global Exception Handling Code --

//AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

#endregion

frmLoader = new FRM_APP_LOADER();
frmLoader.Show();

LoadASM();

FRM_MAIN obj = null;
//Application.Run(new GPT_FORMS.FRM_APP_LOADER());
Application.Run(new GPT_FORMS.FRM_REGISTER(obj));
//Application.Run(new GPT_FORMS.FRM_TRAINLIST());
}
catch (Exception e)
{
LogException("prg  -- " + e.Message);
}
}

#region -----GLOBAL ERROR HANDLERS-----

#endregion

public static void LogException(string msg)
{
try
{
// Create the source, if it does not already exist.
if (!EventLog.SourceExists("SUPREMO"))
{
// An event log source should not be created and immediately used.
// There is a latency time to enable the source, it should be created
// prior to executing the application that uses the source.
// Execute this sample a second time to use the new source.
EventLog.CreateEventSource("SUPREMO", "SKTRC");
//Console.WriteLine("CreatingEventSource");
//Console.WriteLine("Exiting, execute the application a second time to use the source.");
//// The source is created.   Exit the application to allow it to be registered.
//return;
}

EventLog m_EventLog = new EventLog("SKTRC");
m_EventLog.Source = "SUPREMO";
m_EventLog.WriteEntry("Message : " + msg,
EventLogEntryType.Error);
}
catch { }
}

static bool checkChromeInstalled()
{
try
{
string process = "chrome.exe";
string args = "--no-startup-window --start-in-incognito";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = process;
psi.Arguments = args;
var chrome_ps = Process.Start(psi);
if (chrome_ps != null)
{
try
{
//chrome exists and started successully.  exit chrome.
chrome_ps.Kill();
}
catch { }
}
//if reached this far, means chrome exist.
return true;
}
catch
{
//got an error, probably chrome is not installed(not sure however).
return false;
}
}

public static bool IsDotnetCoreInstalled()
{
bool result = false;
try
{
string text = string.Empty;
string value = "dotnet --list-runtimes";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = new Process
{
StartInfo = startInfo
})
{
process.Start();
process.StandardInput.WriteLine(value);
process.StandardInput.Flush();
process.StandardInput.Close();
text = process.StandardOutput.ReadToEnd();
process.WaitForExit();
}
if (!(text.Contains("Microsoft.AspNetCore.App") | text.Contains("Microsoft.NETCore.App")))
{
MessageBox.Show(new Form
{
TopMost = true
}, "Please Install DotNet FrameWork 6\r\nIts Compulsary for PhonePe Bypass\r\nAfter Installing Restart Your Computer and then use this Software for PhonePe Bypass...", "DotNet Framework 6 Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
DialogResult dialogResult = MessageBox.Show("Do You Want to Download .Net FrameWork 6.0.27", "DotNet", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
Process.Start("https://download.visualstudio.microsoft.com/download/pr/37d12f81-b83d-43d8-91be-7c547a2abfe2/4f6bed6c672458dafd805b007509d9ad/dotnet-sdk-6.0.419-win-x64.exe");
}
}
else
{
result = true;
}
}
catch
{
result = true;
}
return result;
}

public static bool CheckForInternetConnection()
{
/*try
{
using (var client = new WebClient())
using (var stream = client.OpenRead("http://www.google.com"))
{
return true;
}
}
catch
{
return false;
}
*/
return true;
}

internal static void CreateHandle(Control ctrl)
{

//SK 22022024
return;
try
{
if (!ctrl.IsHandleCreated)
{
ctrl.CreateControl();
}
}
catch (Exception ex)
{

LogException("Exception in creating handle " + ex.StackTrace + " Mesaage " + ex.Message);

}
}

//SK 22022024
internal static void CreateHandleNew(Control ctrl)
{
try
{
if (!ctrl.IsHandleCreated)
{
ctrl.CreateControl();
}
}
catch (Exception ex)
{
LogException("Exception in creating handle " + ex.StackTrace + " Mesaage " + ex.Message);

}
}

internal static void ShowANdExit(string appName)
{
try
{
Application.UseWaitCursor = false;
}
catch { }
//SK MESSAGE UPDATE OCT 2023
MessageBox.Show("Unauthorised Access Denied.  Apke System mein App Chal Raha hai.", "App - " + appName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
ExitProcess(0u);
}

public static void KillOterProcess()
{

Process currentRunningProcess = Process.GetCurrentProcess();

Process[] listOfProcs = Process.GetProcessesByName(currentRunningProcess.ProcessName);

foreach (Process p in listOfProcs)
{
if (p.Id != currentRunningProcess.Id)
{
p.Kill();
}
}

}
public static int GetCurrentProcessCounts()
{

Process currentRunningProcess = Process.GetCurrentProcess();

Process[] listOfProcs = Process.GetProcessesByName(currentRunningProcess.ProcessName);

return listOfProcs.Length;

}
internal static void LoadASM()
{

#region --- ASM HELPER CODE --

//ASM_HELPER.INIT("TICKET_GPT.GPT_RESOURCES.DLLS..dll", ".dll");

#endregion

}

internal static void CloseLoader()
{
try
{
if (frmLoader != null)
{
frmLoader.Close();
}
}
catch (Exception ex)
{

}
}
}
}
Это cefsharpbrowserautomation.cs файл:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CefSharp;
using CefSharp.OffScreen;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Drawing;

namespace TICKET_GPT.GPT_BL.IRCTC.OPEARTIONS
{
public class CefSharpBrowserAutomation
{

public static void InitCefSettings()
{
try
{

// Initialize CefSharp globally once
//var settings = new CefSettings();
//Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

// Initialize CefSharp once
var settings = new CefSettings
{
CachePath = Path.Combine(Environment.CurrentDirectory, "CefCache"),
PersistSessionCookies = true,
LogSeverity = LogSeverity.Disable,
//WindowlessRenderingEnabled = true,
RemoteDebuggingPort = 8088 // optional but useful for debugging

};
//stealth mode
//Disable WebRTC, WebGL, and Media Device Info
//PC1 settings.CefCommandLineArgs.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.85 Safari/537.36");
//PC1 settings.CefCommandLineArgs.Add("disable-webrtc", "1");
//PC1 settings.CefCommandLineArgs.Add("disable-webgl", "1");
//PC1 settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream", "1");
//Set a normal window size and screen resolution:
//settings.CefCommandLineArgs.Add("window-size", "1920,1080");
// settings.CefCommandLineArgs.Add("device-scale-factor", "1");
//Accept all cookies and enable cache
//PC1 settings.CefCommandLineArgs.Add("disable-application-cache", "0");
//PC1 settings.CefCommandLineArgs.Add("enable-application-cache", "1");
//PC1 settings.CefCommandLineArgs.Add("enable-cookies", "1");

// Recommended for WinForms on newer CEF
settings.CefCommandLineArgs.Add("disable-gpu", "1");
settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1");
settings.CefCommandLineArgs.Add("disable-smooth-scrolling", "1");
//PC1 settings.CefCommandLineArgs.Add("disable-software-rasterizer", "0");
settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1");
//settings.CefCommandLineArgs.Add("force-device-scale-factor", "1");
//PC2 settings.CefCommandLineArgs.Add("high-dpi-support", "1");
//PC2settings.CefCommandLineArgs.Add("disable-site-isolation-trials", "1");
//PC2settings.CefCommandLineArgs.Add("disable-blink-features", "AutomationControlled");
//PC2settings.CefCommandLineArgs.Add("disable-features", "TLS13EarlyData");

settings.LogFile = "cef.log";
//Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
float dpiX, dpiY;

using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
float dpiScale = g.DpiX / 96.0f; // 96 DPI = 100%
dpiX = g.DpiX;
dpiY = g.DpiY;
Console.WriteLine($"DPI: {dpiX} x {dpiY}");
//settings.CefCommandLineArgs.Add("force-device-scale-factor", dpiScale.ToString("0.##"));
}
Cef.Initialize(settings);

//Cef.Initialize(settings);
Console.WriteLine("InitCefSettings Initiaized ");

}
catch (Exception ex)
{
Console.WriteLine("InitCefSettings Error :" + ex.ToString());
}
}

}
}
< /code>
Помогите мне исправить эту проблему. Дайте мне знать, если вы хотите увидеть код любого другого файла.

Подробнее здесь: https://stackoverflow.com/questions/795 ... g-cefsharp
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Winforms искажаются с помощью Cefsharp
    Anonymous » » в форуме C#
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • CefSharp.WinForms «Dock = DockStyle.Fill» без эффекта, черный край. Как заставить ChromiumWebBrowser заполнить TBForm?
    Anonymous » » в форуме C#
    0 Ответы
    24 Просмотры
    Последнее сообщение Anonymous
  • Почему мои данные искажаются с помощью ranges::to?
    Anonymous » » в форуме C++
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous
  • Почему мои данные искажаются с помощью ranges::to?
    Anonymous » » в форуме C++
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous
  • Почему мои данные искажаются с помощью ranges::to?
    Anonymous » » в форуме C++
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»