admin 发表于 2023-7-26 14:02:00

【FBroSharp】浏览器框架C#基础示例源码

本帖最后由 逆風飛翔的瘋狂 于 2023-7-26 14:19 编辑

在大家的支持下,FBrowserCEF3lib浏览器模块C#版已在前几天发布,这里把基础例子和开源地址贴出来给大家简单介绍下,基础功能都是全免费使用。

用过FBrowser火山版或者易版的上手应该很容易,因为基本使用方式异曲同工,只不过一个是中文,一个是英文;


基础例子在线gitee开源地址:https://gitee.com/FloatToPoint/fbro-sharp-test.git


下面是部分代码截图:
初始化代码:
static void Main()
{
            
            FBroSharpInitSet set = new FBroSharpInitSet
            {
                //设置缓存目录
                cache_path = Directory.GetCurrentDirectory() + "\\Cache\\CachePath\\",

                //设置用户目录
                user_data_path = Directory.GetCurrentDirectory() + "\\Cache\\UserPath\\",

                //设置根缓存目录,必须是上面缓存目录的父目录,否则采用独立缓存可能会失效
                root_cache_path = Directory.GetCurrentDirectory() + "\\Cache\\",

                //启用事件消息循环
                multi_threaded_message_loop = true,

                //设置执行子进程,不设置他会默认以当前进程作为子进程
                browser_subprocess_path = Directory.GetCurrentDirectory() + "\\FBroSubprocess.exe",

                //本地化语言
                locale= "zh-CN"
            };

            //创建初始化事件
            InitEvent init_event = new InitEvent();

            //执行初始化
            if (!FBroSharpInitControl.InitPro(set, init_event))
                return;


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            //关闭框架释放资源
            FBroSharpInitControl.Shutdown(false);

      }

创建浏览器代码:
public static void CreatBrowser(string title, string url, IntPtr parent_window, int x, int y, int width, int height)
      {
            //开始创建浏览器
            FBroSharpWindowsInfo windows_info = new FBroSharpWindowsInfo
            {
                parent_window = parent_window,
                x = x,
                y = y,
                width = width,
                height = height,
                window_name = title
            };

            //创建浏览器事件回调类
            BrowserEvent browser_event = new BrowserEvent();

            //设置运行环境
            //FBroSharpRequestContextSet contextSet = new FBroSharpRequestContextSet();
            //contextSet.cache_path = Directory.GetCurrentDirectory() + "\\Cache\\other cache\"; ;

            //FBroSharpRequestContext request_context = (FBroSharpRequestContext)FBroSharpRequestContext.CreateContext(contextSet);
            //Console.WriteLine("缓存目录:" + request_context.GetCachePath());

            //设置不需要的事件
            //FBroSharpEventDisableControl event_contrl = new FBroSharpEventDisableControl();
            //event_contrl.disableGetAudioHandler = true;


            //设置传递参数
            //FBroSharpDictionaryValue extra_info = new FBroSharpDictionaryValue();//.Creat();
            //extra_info.SetString("传参测试", "这是创建浏览器的时候传递过来的参数");

            if (FBroSharpControl.CreatBrowser(url, windows_info, default, default /*request_context*/, default/*extra_info*/, browser_event, default/*event_contrl*/))
                Console.WriteLine("true");
      }
运行效果图:


更多的细节,就不细说了,很多,代码都在上方的开源库里面,欢迎各位下载测试,如有BUG和好的建议可以来群里反馈;

还有些高级进阶例子后续完善中

C#版入门手册和安装使用方式说明链接:
https://docs.qq.com/doc/DR09NTXlycEJPQ2N2








mosheng 发表于 2023-7-26 14:02:00

C#的越来越完善了{:8_494:}
页: [1]
查看完整版本: 【FBroSharp】浏览器框架C#基础示例源码