Очистить текстовый html-код webview2: >
Код: Выделить всё
private async void button6_Click_1(object sender, EventArgs e)
{
{
try
{
if (tabkont.TabPages.Count > 0)
{
TabPage selectedTab = tabkont.SelectedTab;
Microsoft.Web.WebView2.WinForms.WebView2 webView2 = selectedTab.Controls.Find("webView2", true).FirstOrDefault() as Microsoft.Web.WebView2.WinForms.WebView2;
if (webView2 != null)
{
await webView2.CoreWebView2.ExecuteScriptAsync($"SetText(``);");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}");
}
}
я использую этот код для удаления html-текста webview2, но почему-то только я могу удалить html-текст первой вкладки webview2, но я хочу также выбрать другие вкладки html-текста webview2, чтобы они были заменены на пустой текст.
я использую этот код для удаления html-текста webview2, но почему-то только я могу удалить html-текст первой вкладки webview2. p>
я также использую этот код для создания вкладок
Код: Выделить всё
private int tabCount = 1;
private async void button1_Click(object sender, EventArgs e)
{
if (tabCount == 7)
{
MessageBox.Show("Tab Limit is 7!!", "Error", MessageBoxButtons.OK);
}
else {
TabPage newTab = new TabPage($"Tab {tabCount + 1}");
var webView2 = new Microsoft.Web.WebView2.WinForms.WebView2
{
Dock = DockStyle.Fill
};
await webView2.EnsureCoreWebView2Async(null);
webView2.Source = new Uri($"file:///{Directory.GetCurrentDirectory()}/Kod/index.html");
newTab.Controls.Add(webView2);
tabkont.TabPages.Add(newTab);
tabCount++;
tabkont.SelectTab(newTab);
tabadd.Left = tabadd.Left + 55;
tabdel.Left = tabdel.Left + 55;
}
}
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.IO;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using Microsoft.Web.WebView2.WinForms;
using VisualStudioTabControl;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Agazistan_HtmlTextEditor
{
public partial class agazistan_htmltexteditor : Form
{
public agazistan_htmltexteditor()
{
InitializeComponent();
InitializeAsync();
}
private async void InitializeAsync()
{
try
{
await webView2.EnsureCoreWebView2Async(null);
webView2.CoreWebView2.Navigate(new Uri($"file:///{Directory.GetCurrentDirectory()}/Kod/index.html").ToString());
}
catch (Exception ex)
{
MessageBox.Show($"Error initializing WebView2: {ex.Message}", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
когда я буду использовать кнопку «Очистить» на первой вкладке webview2 html-текст
до: не удалена первая вкладка webview2 html-текст до
после: после нажатия кнопки «sil» на первой страницено другие страницы, на которых кнопка «sil» не очищает весь текст внутри webview2 html
Страница «Kod 1» не открывается позже, приложение открыто, оно уже находится в редакторе winforms
если этот код работает, я также могу удалить весь html-текст моей вкладки webview2, а не html-текст первой вкладки webview2.
Подробнее здесь: https://stackoverflow.com/questions/792 ... tabcontrol