I am trying to build a simple Python Editor with ScintillaNET and am now trying to return the input.
I have a class PythonScriptView:
public class PythonScriptView : Scintilla
{
// setup python syntax highlighting
}
and a Form which consists of a PythonScriptView component and an OK button. Inside this class I want to build a function which shows the form and returns the Text property of my PythonScriptView. I did this for another small dialog window which uses a textbox as input field and are now trying the same with the scintilla editor:
public string GetUserInput()
{
ShowDialog();
return ScriptView.Text; // ScriptView is of Type PythonScriptView
}
When I am running the app I get the following error message:
An unhandled exception of type 'System.AccessViolationException' occurred in ScintillaNET.dll
Does anyone know how to solve this? How else can I read the Text property?
Edit:
Seems like I cannot access any properties or methods from this class
I was having this same issue and it appears that due to the way ScintillaNET works you are not able to access any properties once the element is disposed do to the form closing. I found a work around by adding the following event and property to my Form.
private void FormClosing(object sender, FormClosingEventArgs e)
{
CachedText = scintilla.Text;
}
public string CachedText { get; private set; }
Related
I'm trying to make a C# script for unity to create dialogue using 'Ink.Runtime' and this procedure in the code is attempting to switch the text to a new line when the condition is met. But when I attempt to run the script the following error is displayed:
Assets\C# Scripts\DialogueManager.cs(60,13): error CS0103: The name 'dialogueText' does not exist in the current context
Here's the relevant string of code written below
private void ContinueStory()
{
if (currentStory.canContinue)
{
dialogueText.text = currentStory.Continue();
}
else
{
ExitDialogueMode();
}
}
I think an issue may be that I was previously using the new input system but switched back to the old one and may have forgotten to change this string in using that input system. I'm relatively new to programming in C# and so help would be much appriciated!
It's tough from the small snippet provided but from the error it looks like the assignment is outside the context of where your dialogText is accessible. Look at your modifier on how you instantiated the dialogText object and either change it to internal or public or pass the object in the method so it is within the context you are trying to change it.
I am trying to create my first UWP C# app. When the button named 'Button' is clicked, JSON shows up within the text box named 'TextBox'.
I am trying to work out how I can access only one part of the JSON text (data.best_day.text) for example (in JavaScript) data.best_day.text would give 18 hrs 3 mins. I would like to do the same for this UWP app. I have read some resources but they didn't work or were way too complex to understand. Any help would be greatly appreciated. :)
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace WakaTime
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var client = new HttpClient();
var text = await client.GetStringAsync("https://wakatime.com/share/#DontBugMie/bef7afe4-102d-47a9-9678-6335510ebedd.json");
TextBox.Text = text;
}
}
}
If you are confident in the path, try this
using System.Text.Json;
...
var jsonDoc = JsonDocument.Parse(text);
var best_day = jsonDoc.RootElement.GetProperty("data").GetProperty("best_day").GetProperty("text").GetString();
TextBox.Text = best_day;
If you need more than one value, then it would be better to create a model (DTO) and deserialize to it
Get the actual JSON and go to a site which converts JSON to C# (Search for that). Also depending on the version Visual Studio, it may have the menu option of Edit - Paste Special - Paste JSON As CLasses which will also work. You will now have classes which you can add to your project which are based off of the JSON.
Then in your code deserialize to the model (or a list of the models). Once it is deserialized into an instance, access best_day as needed.
This question already has an answer here:
Show an HTML file of my Project in WebBrowser control at run-time
(1 answer)
Closed 3 years ago.
I'm working on a Winforms project and want to display the About page content from an HTML file.
I used the WebBrowser control for that but even though it works, I still get the following error message upon opening the solution or building the project:
Error Message
Is there any way to fix it or ignore it?
Here's the method call from the About page class:
private void displayAboutContent()
{
this.labelVersion.Text = string.Format(#"Version: {0}",BoostEngine.r_CurrentVersion);
UITools.displayHTMLPage(m_WebBrowser, m_ResourceName);
}
and the UI Tools static class:
public static class UITools
{
public static void displayHTMLPage(WebBrowser i_WebBrowser, string i_ResourceName)
{
Uri uri = new Uri(getFilepath(i_ResourceName));
i_WebBrowser.ScriptErrorsSuppressed = true;
i_WebBrowser.Navigate(uri);
}
private static string getFilepath(string i_ResourceName)
{
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string filePath = Path.Combine(projectPath, string.Format("Resources\\{0}.html", i_ResourceName));
return filePath;
}
}
P.S.
I'm using this code on another form but receive the error only for the About page.
Also important to note, I'm using a Parallels VM on Mac.
Thanks!
I don't know what is running code during solution load or compile, you might look in your project file for any targets that have been added.
But to simply get around the problem you could choose to not Navigate if the file doesn't exist:
if(System.IO.File.Exists("c:\\whatever"))
{
i_WebBrowser.Navigate(uri);
}
If you do that you might consider loading a page that is guaranteed to be there or load a string of html to make it a little more user friendly with an appropriate message.
I am not a seasoned pro at C# and am running into an error I cannot find a discrete solution to. Currently I have one class that is part of my namespace
namespace BlackBoxStudio
{
public partial class Project : Form
{
This Project class is what implements the various functions of my form. What I am trying to do is make a label.text field accessable to another .cs class within the same namespace. As so, I have made the corresponding fields public:
public string lb_InformationText
{
get { return lb_Information.Text; }
set { lb_Information.Text = value; }
}
To call these I get or set methods in my RsaFunctions class I make a new private project as so:
namespace BlackBoxStudio
{
class RsaFunctions
{
//private Project proj = new Project();
However the line that is commented our causes my vshost32.exe application to fail and the program dies. Why is this causing the vshost32.exe to fail when I un-comment the corresponding line? Or how could I better structure my classes so this does not happen? Any tips would be much appreciated about my strategy for making new classes and such.
I found the similar questions how to call java script function from activex or dll in c# but this is not provide me solution.than i continue my searching finally i got msdn link on this
http://msdn.microsoft.com/en-us/library/ms171712.aspx
To access DOM from a UserControl hosted in Internet Explorer
Create your own custom derived class of the UserControl class. For more information, see How to: Author Composite Controls.
Place the following code inside of your Load event handler for your UserControl:
HtmlDocument doc = null;
private void UserControl1_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}
Unfortunately I am still unable to get DOM object in my class.I have try to see what i get in this.Site so i put it on a messagebox
MessageBox.Show(this.Site.ToString());
which shows me strange thing that is
System.Windows.Forms.Control+AxSourcingSite
please help me..