public void ClickCheckbox(string anchorId) { isDocumentComplete = false; HTMLInputElement input = GetCheckboxElement(anchorId); input.click(); }
private static void AddNewTeacher(HTMLElement sender) { // Get name input and it's value HTMLInputElement input = (sender.ParentElement.ParentElement.GetElementsByClassName("form-group")[0].Children.Where(x => x.Id == ("teacher-name")).First() as HTMLInputElement); string newTeacherName = input.Value; if (newTeacherName == "") { return; } plan.teachers.Add(new User(newTeacherName, new bool[5], new int[5], new int[5])); HTMLElement div = Gid("teachers"); HTMLDivElement card = new HTMLDivElement(); card.ClassName = "card card-body"; card.InnerHTML += "<p><strong>" + newTeacherName + "</strong></p>"; HTMLButtonElement setHours = new HTMLButtonElement(); setHours.Name = (plan.teachers.Count - 1).ToString(); setHours.ClassName = "btn btn-primary teacher-click"; setHours.SetAttribute("data-toggle", "modal"); setHours.SetAttribute("data-target", "#setHoursModal"); setHours.InnerHTML = "Nastavit hodiny"; setHours.OnClick += (e) => { EditHoursClick(setHours, true); }; card.AppendChild(setHours); div.AppendChild(card); input.Value = ""; // Allow only one teacher Gid("add-new-teacher-modal-button").Remove(); }
public static HTMLInputElement TextBox(Attributes init) { var f = new HTMLInputElement(); init?.InitInputElement(f); return(f); }
public static void RefactoredLogin(WebUtil w, string username, string password) { HTMLDivElement loginDiv = w.GetElementById("loginForm") as HTMLDivElement; if (loginDiv != null) { IHTMLElementCollection inputs = loginDiv.getElementsByTagName("input"); foreach (IHTMLElement element in inputs) { if (element is HTMLInputElement) { HTMLInputElement input = element as HTMLInputElement; switch (input.name) { case "username": input.value = username; break; case "password": input.value = password; break; case "login": w.submitClick(input as IHTMLElement); break; } } } } }
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { switch (Task) { case 1: HTMLDocument myDoc = new HTMLDocumentClass(); myDoc = (HTMLDocument)axWebBrowser1.Document; // a quick look at the google html source reveals: // <INPUT maxLength="256" size="55" name="q"> // HTMLInputElement otxtSearchBox = (HTMLInputElement)myDoc.all.item("q", 0); otxtSearchBox.value = "intel corp"; // google html source for the I'm Feeling Lucky Button: // <INPUT type=submit value="I'm Feeling Lucky" name=btnI> // HTMLInputElement btnSearch = (HTMLInputElement)myDoc.all.item("btnI", 0); btnSearch.click(); Task++; break; case 2: // continuation of automated tasks... break; } }
public void Render() { var labelWelcome = new HTMLLabelElement { InnerHTML = "Welcome to Pomodoro!", Style = { FontSize = "32px", Margin = "10px" } }; _textBoxName = new HTMLInputElement { Placeholder = "Enter name…", Value = "PomodoroBridgeClient" }; _table = new HTMLTableElement(); var buttonGetAll = new HTMLButtonElement { InnerHTML = "Get all", OnClick = ev => RefreshList() }; var buttonStart = new HTMLButtonElement { InnerHTML = "Start", OnClick = ev => { _api.Start(_textBoxName.Value); RefreshList(); } }; var buttonStop = new HTMLButtonElement { InnerHTML = "Stop", OnClick = ev => { _api.Stop(_textBoxName.Value); RefreshList(); } }; // Add to the document body var htmlBodyElement = Document.Body; htmlBodyElement.AppendChild(labelWelcome); htmlBodyElement.AppendChild(new HTMLBRElement()); htmlBodyElement.AppendChild(_textBoxName); htmlBodyElement.AppendChild(new HTMLBRElement()); htmlBodyElement.AppendChild(buttonGetAll); htmlBodyElement.AppendChild(buttonStart); htmlBodyElement.AppendChild(buttonStop); htmlBodyElement.AppendChild(new HTMLBRElement()); htmlBodyElement.AppendChild(_table); }
protected override void Initialise() { base.Initialise(); this.Text = "Run Interface"; this.Width = "400px"; this.Height = "100px"; var Input = new HTMLInputElement(); Input.Style.Position = Position.Absolute; Input.Style.Left = "5px"; Input.Style.Top = "5px"; FillHorizontalControlWithParent(Input, 5); Input.OnKeyUp = (ev) => { var kev = ev.As <KeyboardEvent>(); if (kev.KeyCode == 13) { if (string.IsNullOrWhiteSpace(Input.Value)) { ServerApplication.StartFromURI(Input.Value); } Input.Value = ""; } }; //FillHorizontalControlWithParent() //this.Body.AppendChild() }
public static void Test() { HTMLInputElement input = new HTMLInputElement(); input.OnChange += (ev) => { // Tests if ev.CurrentTarget.Value compiles Console.WriteLine("ev.CurrentTarget.Value: " + ev.CurrentTarget.Value); // Tests if ev.IsMouseEvent() compiles Console.WriteLine("IsMouseEvent: " + ev.IsMouseEvent()); }; HTMLAnchorElement anchor = new HTMLAnchorElement(); anchor.OnClick += (ev) => { // Tests if ev.CurrentTarget.Href compiles Console.WriteLine("ev.CurrentTarget.Href: " + ev.CurrentTarget.Href); }; // Test if Document.GetElementById<>() compiles HTMLDivElement div = Document.GetElementById <HTMLDivElement>("div1"); // Tests if Element is still a superclass of all the element classes and the following code compiles HTMLElement element; element = new HTMLInputElement(); element = new HTMLTextAreaElement(); }
static void SaveTheme() { if (!Window.Confirm("Save theme ?\r\nThis might take up to a minute, don't close this page")) { return; } HTMLInputElement bgm = Document.GetElementById <HTMLInputElement>("EnableBGMchb"); t.BGM = bgm.Checked; t.TopScreenFrameType = (uint)TopFrameType.SelectedIndex; t.BotScreenFrameType = (uint)BotFrameType.SelectedIndex; ApplyColorsToTheme(); DoActionWithloading(() => { byte[] themedata = t.MakeTheme(); Lz11Compression c = new Lz11Compression(); MemoryStream inData = new MemoryStream(themedata); MemoryStream compData = new MemoryStream(); if (Document.GetElementById <HTMLInputElement>("Fastbuild").Checked) { c.ArchiveNoCompression(inData, compData); } else { c.Compress(inData, compData); } Uint8Array dwn = new Uint8Array(compData.ToArray()); Script.Write("downloadBlob(dwn,'Body_LZ.bin','application/octet-stream');"); }); }
/// <summary> /// Login helper method. /// </summary> /// <param name="userNameTextBoxID">The user name text box ID.</param> /// <param name="passwordTextBoxID">The password text box ID.</param> /// <param name="pageDocument">The page document.</param> private static void LoginInternal(string userNameTextBoxID, string passwordTextBoxID, HTMLDocument pageDocument) { HTMLInputElement userIDControl = (HTMLInputElement)pageDocument.all.item(userNameTextBoxID, 0); if (userIDControl != null) { if (string.IsNullOrEmpty(UserId)) { Console.Write(UserIDPrompt); UserId = Console.ReadLine(); } userIDControl.value = UserId; } HTMLInputElement passwordControl = (HTMLInputElement)pageDocument.all.item(passwordTextBoxID, 0); if (passwordControl != null) { if (string.IsNullOrEmpty(Password)) { Console.Write(PasswordPromp); Password = Console.ReadLine(); } passwordControl.value = Password; passwordControl.form.submit(); } }
public static void Main() { // HTML ResultBox = Document.GetElementById <HTMLDivElement>("expr-resultbox"); InputExpression = Document.GetElementById <HTMLInputElement>("tExpression"); InputExpression.OnInput = OnInputExpression; OnInputExpression(null); // INSTRUCTIONS // ============= // // After building (Ctrl + Shift + B) this project, // browse to the /bin/Debug or /bin/Release folder. // // A new bridge/ folder has been created and // contains your projects JavaScript files. // // Open the bridge/index.html file in a browser by // Right-Click > Open With..., then choose a // web browser from the list. // // This application will then run in the browser // and you will be able to test it. // }
/// <summary> /// Show the inline free-text editor on top of the text. /// </summary> /// <param name="opt_quietInput">True if editor should be created without /// focus.Defaults to false.</param> public override void showEditor_(bool opt_quietInput) { this.workspace_ = (WorkspaceSvg)this.sourceBlock_.workspace; var quietInput = opt_quietInput || false; if (!quietInput && (goog.userAgent.MOBILE || goog.userAgent.ANDROID || goog.userAgent.IPAD)) { // Mobile browsers have issues with in-line textareas (focus & keyboards). var newValue = Window.Prompt(Msg.CHANGE_VALUE_TITLE, this.text_); if (this.sourceBlock_ != null) { newValue = this.callValidator(newValue); } this.setValue(newValue); return; } WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_()); var div = WidgetDiv.DIV; // Create the input. var htmlInput = (HTMLInputElement) goog.dom.createDom(goog.dom.TagName.INPUT, "blocklyHtmlInput"); htmlInput.SetAttribute("spellcheck", this.spellcheck_.ToString()); var fontSize = (FieldTextInput.FONTSIZE * this.workspace_.scale) + "pt"; div.Style.FontSize = fontSize; htmlInput.Style.FontSize = fontSize; /** @type {!HTMLInputElement} */ FieldTextInput.htmlInput_ = htmlInput; div.AppendChild(htmlInput); htmlInput.Value = htmlInput.DefaultValue = this.text_; htmlInput["oldValue_"] = null; this.validate_(); this.resizeEditor_(); if (!quietInput) { htmlInput.Focus(); htmlInput.Select(); } // Bind to keydown -- trap Enter without IME and Esc to hide. htmlInput["onKeyDownWrapper_"] = Core.bindEventWithChecks_(htmlInput, "keydown", this, new Action <KeyboardEvent>(this.onHtmlInputKeyDown_)); // Bind to keyup -- trap Enter; resize after every keystroke. htmlInput["onKeyUpWrapper_"] = Core.bindEventWithChecks_(htmlInput, "keyup", this, new Action <Event>(this.onHtmlInputChange_)); // Bind to keyPress -- repeatedly resize when holding down a key. htmlInput["onKeyPressWrapper_"] = Core.bindEventWithChecks_(htmlInput, "keypress", this, new Action <Event>(this.onHtmlInputChange_)); htmlInput["onWorkspaceChangeWrapper_"] = new Action <Events.Abstract>(this.resizeEditor_); this.workspace_.addChangeListener((Action <Events.Abstract>)htmlInput["onWorkspaceChangeWrapper_"]); }
public ButtonClearCompleted(string selector) { btnClearCompleted = (HTMLInputElement)Document.GetElementById(selector); btnClearCompleted.OnClick += new Action <MouseEvent <HTMLInputElement> >(delegate { OnClick?.Invoke(); }); }
public static HTMLInputElement CheckBox(Attributes init) { var input = new HTMLInputElement { type = "checkbox" }; init?.InitInputElement(input); return(input); }
public static HTMLInputElement RadioButton(Attributes init) { var input = new HTMLInputElement { type = "radio" }; init?.InitInputElement(input); return(input); }
public static HTMLInputElement FileInput(Attributes init) { var input = new HTMLInputElement { type = "file" }; init?.InitInputElement(input); return(input); }
public static void Main() { var plus = new Sum(); var button = new HTMLButtonElement() { InnerHTML = "Click me", OnClick = (ev) => { Console.WriteLine("Success"); } }; var inputFirst = new HTMLInputElement() { Type = InputType.Number, Name = "InpurFirst", }; var inputSecond = new HTMLInputElement() { Type = InputType.Number, Name = "SecondFirst", }; var buttonSum = new HTMLButtonElement() { InnerHTML = "plus", OnClick = (ev) => { plus.First = int.Parse(inputFirst.Value); plus.Second = int.Parse(inputSecond.Value); Console.WriteLine($"sum: {plus.Result}"); } }; var div = new HTMLDivElement(); Document.Body.AppendChild(button); Document.Body.AppendChild(div); div.AppendChild(inputFirst); div.AppendChild(inputSecond); div.AppendChild(buttonSum); var calculator = new Calculator(); calculator.Plus(10, 20); calculator.Minus(10, 20); calculator.Multiply(10, 20); calculator.Divide(10, 20); calculator.Pow(2, 4); calculator.Sqrt(9); Console.WriteLine("Console message after added button"); }
private static bool GetInputValue(HTMLInputElement source, out double number) { number = Script.ParseFloat(source.Value); if (double.IsNaN(number)) { return(false); } return(true); }
static Task <string> FileRead(HTMLInputElement fileInput) { var file = fileInput.Files[0]; dynamic fileReader = Script.Write <dynamic>("new FileReader()"); TaskCompletionSource <string> task = new TaskCompletionSource <string>(); fileReader.onload = (Action <Event>)(e => task.SetResult(fileReader.result)); fileReader.readAsText(file); return(task.Task); }
/// <summary> /// Creates the dom for a single block option. Includes checkbox, label, and div /// in which to inject the preview block. /// </summary> /// <returns>Root node of the selector dom which consists of a /// checkbox, a label, and a fixed size preview workspace per block.</returns> public Element createDom() { // Create the div for the block option. var blockOptContainer = goog.dom.createDom("div", new Dictionary <string, string> { { "id", this.blockType }, { "class", "blockOption" } }, ""); // Empty quotes for empty div. // Create and append div in which to inject the workspace for viewing the // block option. var blockOptionPreview = goog.dom.createDom("div", new Dictionary <string, string> { { "id", this.blockType + "_workspace" }, { "class", "blockOption_preview" } }, ""); blockOptContainer.AppendChild(blockOptionPreview); // Create and append container to hold checkbox and label. var checkLabelContainer = goog.dom.createDom("div", new Dictionary <string, string> { { "class", "blockOption_checkLabel" } }, ""); blockOptContainer.AppendChild(checkLabelContainer); // Create and append container for checkbox. var checkContainer = goog.dom.createDom("div", new Dictionary <string, string> { { "class", "blockOption_check" } }, ""); checkLabelContainer.AppendChild(checkContainer); // Create and append checkbox. this.checkbox = (HTMLInputElement)goog.dom.createDom("input", new Dictionary <string, string> { { "type", "checkbox" }, { "id", this.blockType + "_check" } }, ""); checkContainer.AppendChild(this.checkbox); // Create and append container for block label. var labelContainer = goog.dom.createDom("div", new Dictionary <string, string> { { "class", "blockOption_label" } }, ""); checkLabelContainer.AppendChild(labelContainer); // Create and append text node for the label. var labelText = goog.dom.createDom("p", new Dictionary <string, string> { { "id", this.blockType + "_text" } }, this.blockType); labelContainer.AppendChild(labelText); this.dom = blockOptContainer; return(this.dom); }
private void InitCheckboxItem() { _cbItem = new HTMLInputElement() { Type = InputType.Checkbox }; _cbItem.OnClick += new Action <MouseEvent <HTMLInputElement> >(delegate { _complete = !_complete; CompleteClicked?.Invoke(_complete); }); }
private void setDayText(HTMLInputElement htmlInput, TextBox textBox) { if (htmlInput.value != String.Empty) { textBox.Text = htmlInput.value; } else { textBox.Text = "IN"; } }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (webBrowser1.ReadyState == WebBrowserReadyState.Complete) { if (webBrowser1.Url.ToString() == "http://intranet.cougarautomation.net/Cats/Movements/MyMovements.aspx") { Web_V1 = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance; HTMLDocument movements = new HTMLDocument(); movements = (HTMLDocument)Web_V1.Document; if (thisWeek) { htmlMonInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxThisMonday", 0); htmlTueInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxThisTuesday", 0); htmlWedInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxThisWednesday", 0); htmlThuInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxThisThursday", 0); htmlFriInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxThisFriday", 0); } else { htmlMonInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxNextMonday", 0); htmlTueInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxNextTuesday", 0); htmlWedInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxNextWednesday", 0); htmlThuInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxNextThursday", 0); htmlFriInput = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_TextBoxNextFriday", 0); } setDayText(htmlMonInput, mondayInput); setDayText(htmlTueInput, tuesdayInput); setDayText(htmlWedInput, wednesdayInput); setDayText(htmlThuInput, thursdayInput); setDayText(htmlFriInput, fridayInput); submitButton = (HTMLInputElement)movements.all.item("ContentPlaceHolder1_ButtonAccept", 0); okButton.Enabled = true; mondayInput.Enabled = true; tuesdayInput.Enabled = true; wednesdayInput.Enabled = true; thursdayInput.Enabled = true; fridayInput.Enabled = true; } } } catch (Exception exception) { MessageBox.Show("Unable to connect to movements page, please check your connection"); this.Close(); } }
private void button4_Click(object sender, EventArgs e) { HTMLDocument document = ((HTMLDocument)w.IE.Document); HTMLInputElement otxtSearchBox = (HTMLInputElement)document.getElementById("masthead-search-term"); otxtSearchBox.value = this.query.Text; IHTMLElement searchButton = (IHTMLElement)document.getElementById("search-btn"); searchButton.click(); }
private HTMLInputElement GetInputNumberElement(HTMLInputElement enableElement, double initialValue, int widthInDigits, double?step = 1, double?min = 0, double?max = null) { var element = new HTMLInputElement() { Type = InputType.Number, Value = initialValue.ToString(), OnKeyUp = (ev) => { if (ev.IsKeyboardEvent()) { var kev = ev as KeyboardEvent <HTMLInputElement>; if (kev != null) { if (object.Equals(kev["keyCode"], 13)) { ev.PreventDefault(); DrawButton.Click(); } } } } }; if (enableElement != null) { element.Disabled = !enableElement.Checked; var elements = GetElementListToEnable(enableElement); elements.Add(element); } if (step.HasValue) { element.Step = step.ToString(); } if (min.HasValue) { element.Min = min.ToString(); } if (max.HasValue) { element.Max = max.ToString(); } element.Style.Width = widthInDigits + "em"; element.Style.Margin = "5px"; return(element); }
private static bool GetInputValue(HTMLInputElement source, out int number) { var d = Script.ParseFloat(source.Value); if (double.IsNaN(d)) { number = 0; return(false); } number = (int)Math.Round(d); return(true); }
private List <HTMLInputElement> GetElementListToEnable(HTMLInputElement element) { var ce = element["toEnable"]; List <HTMLInputElement> elements; if (ce == null || (elements = ce as List <HTMLInputElement>) == null) { elements = new List <HTMLInputElement>(); element["toEnable"] = elements; } return(elements); }
protected virtual void SetValue(InternetExplorer browser, string key, string value) { try { HTMLDocument doc = (HTMLDocument)browser.Document; HTMLInputElement input = (HTMLInputElement)doc.getElementById(key); input.value = value; } catch { return; } }
private void Render(HTMLElement root) { // Create HTML elements: var headerDiv = new HTMLDivElement(); _todoDiv = new HTMLDivElement(); root.appendChild(headerDiv); root.appendChild(_todoDiv); // Header (to do item creation): var input = new HTMLInputElement(); var addButton = new HTMLButtonElement { innerHTML = "Add", className = "btn btn-primary", style = { margin = "10px" }, disabled = true }; input.onkeyup = e => { if (e?.keyCode == 13) { addButton.click(); } else { addButton.disabled = string.IsNullOrEmpty(input.value); } return(null); }; addButton.onclick = e => { AddTodoItem(input.value); input.value = string.Empty; input.onkeyup(null); return(null); }; _progressLabel = new HTMLLabelElement(); headerDiv.appendChild(input); headerDiv.appendChild(addButton); headerDiv.appendChild(new HTMLBRElement()); headerDiv.appendChild(_progressLabel); headerDiv.appendChild(new HTMLBRElement()); headerDiv.appendChild(new HTMLBRElement()); }
private static void ImageCanvasClick(MouseEvent <HTMLCanvasElement> arg) { if (arg.Target.Id != Theme.Name_TopScr && arg.Target.Id != Theme.Name_BotScr) { HTMLInputElement chb = Document.GetElementById <HTMLInputElement>(arg.Target.Id + "-CHB"); if (!chb.Checked) { Window.Alert("This image is not enabled"); return; } } ImageInputSenderID = arg.Target.Id; Document.GetElementById <HTMLInputElement>("ImageUpload").Click(); }
public Layout(PlotSettings settings) { var plotter = new TinyPlotter(settings); var exprInput = new HTMLInputElement { Type = InputType.Text }; exprInput.Value = "sin(3x)"; var evalInput = new HTMLInputElement { Type = InputType.Text }; evalInput.Value = "plus(5^2, sin(div(pi, 2)))"; var variableInput = new HTMLInputElement { Type = InputType.Text }; variableInput.Value = "x"; var deltaXInput = new HTMLInputElement { Type = InputType.Text }; deltaXInput.Value = "0.005"; var xminInput = new HTMLInputElement { Type = InputType.Text }; xminInput.Value = settings.Viewport.XMin.ToString(); var xmaxInput = new HTMLInputElement { Type = InputType.Text }; xmaxInput.Value = settings.Viewport.XMax.ToString(); var yminInput = new HTMLInputElement { Type = InputType.Text }; yminInput.Value = settings.Viewport.YMin.ToString(); var ymaxInput = new HTMLInputElement { Type = InputType.Text }; ymaxInput.Value = settings.Viewport.YMax.ToString(); var resultDiv = new HTMLDivElement(); resultDiv.Style.FontSize = "18px"; resultDiv.Style.MaxWidth = "300px"; var btnPlot = new HTMLButtonElement { InnerHTML = "Plot with derivative", OnClick = ev => { Func<HTMLInputElement, bool> IsNaN = x => double.IsNaN(Script.ParseFloat(x.Value)); var isNotValid = exprInput.Value == "" || variableInput.Value == "" || IsNaN(deltaXInput) || IsNaN(xminInput) || IsNaN(xmaxInput) || IsNaN(yminInput) || IsNaN(ymaxInput); if (isNotValid) { Write("<h1 style='color:red'>Input is not valid!</h1>", resultDiv); return; } var result = Parser.TryParseInput(exprInput.Value); if (result.WasSuccessful) { // set the settings plotter.Settings.StepX = Script.ParseFloat(deltaXInput.Value); plotter.Settings.Viewport.XMin = Script.ParseFloat(xminInput.Value); plotter.Settings.Viewport.XMax = Script.ParseFloat(xmaxInput.Value); plotter.Settings.Viewport.YMin = Script.ParseFloat(yminInput.Value); plotter.Settings.Viewport.YMax = Script.ParseFloat(ymaxInput.Value); resultDiv.InnerHTML = ""; var f = result.Value; var df = Expr.Differentiate(f, variableInput.Value); var fLambda = Expr.Lambdify(f, variableInput.Value); var dfLambda = Expr.Lambdify(df, variableInput.Value); var curveColor = RandomColor(); plotter.Settings.Curves.Clear(); plotter.Settings.Curves.Add(new Curve { Map = fLambda, Color = curveColor }); plotter.Settings.Curves.Add(new Curve { Map = dfLambda, Color = Grayscale(curveColor) }); plotter.Draw(); var rgbCurveColor = RGB(curveColor); var rgbGrayColor = RGB(Grayscale(curveColor)); var msgParsed = "<strong style='color:" + rgbCurveColor + "'>" + f.ToString() + "</strong>"; var derivative = "<strong style='color:" + rgbGrayColor + "'>" + df.ToString() + "</strong>"; Write("<hr /> Parsed: <br />" + msgParsed + "<br /> Derivative: <br /> " + derivative + "<hr />", resultDiv); } else { var error = string.Join("<br />", result.Expectations); Write("<h1 style='color:red'>" + error + "</h1>", resultDiv); } } }; var btnEvaluate = new HTMLButtonElement { InnerHTML = "Evaluate", OnClick = ev => { if (evalInput.Value == "") { Write("<h1 style='color:red'>Input is not valid!</h1>", resultDiv); return; } var result = Parser.TryParseInput(evalInput.Value); if (result.WasSuccessful) { resultDiv.InnerHTML = ""; var expression = result.Value; var eval = Expr.Evaluate(expression); Write("<h4 style='color:green'>" + "Parsed: " + expression.ToString() + "<br />" + "Answer: " + eval.ToString() + "</h4>", resultDiv); } else { var error = string.Join("<br />", result.Expectations); Write("<h1 style='color:red'>" + error + "</h1>", resultDiv); } } }; var slider = new HTMLInputElement { Type = InputType.Range }; btnEvaluate.Style.Width = "90%"; btnEvaluate.Style.Margin = "5px"; btnEvaluate.Style.Height = "40px"; btnPlot.Style.Margin = "5px"; btnPlot.Style.Height = "40px"; btnPlot.Style.Width = "90%"; var layout = Table( Row(Table( Row(Label("Expression"), exprInput), Row(Label("Variable"), variableInput), Row(Label("XAxis step"), deltaXInput), Row(Label("XMin"), xminInput), Row(Label("XMax"), xmaxInput), Row(Label("YMin"), yminInput), Row(Label("YMax"), ymaxInput), Row(btnPlot, 2), Row(new HTMLHRElement(), 2), Row(Label("Expression"), evalInput), Row(btnEvaluate, 2), Row(resultDiv, 2)), Table( Row(plotter.Canvas))) ); this.container = layout; }
private static bool GetInputValue(HTMLInputElement source, out int number) { var d = Script.ParseFloat(source.Value); if (double.IsNaN(d)) { number = 0; return false; } number = (int)Math.Round(d); return true; }
private static bool GetInputValue(HTMLInputElement source, out double number) { number = Script.ParseFloat(source.Value); if (double.IsNaN(number)) { return false; } return true; }
private HTMLInputElement GetCheckboxElement(bool isChecked) { var checkbox = new HTMLInputElement { Type = InputType.Checkbox, Checked = isChecked, }; // Extend the checkbox var elements = GetElementListToEnable(checkbox); Action<Event<HTMLInputElement>> enableInputs = (ev) => { foreach (var control in elements) { control.Disabled = !checkbox.Checked; } }; checkbox.OnChange = enableInputs; //var label = new HTMLLabelElement //{ // InnerHTML = title //}; //label.Style.Margin = "5px"; //label.AppendChild(checkbox); //if (container != null) //{ // container.AppendChild(label); //} return checkbox; }
private List<HTMLInputElement> GetElementListToEnable(HTMLInputElement element) { var ce = element["toEnable"]; List<HTMLInputElement> elements; if (ce == null || (elements = ce as List<HTMLInputElement>) == null) { elements = new List<HTMLInputElement>(); element["toEnable"] = elements; } return elements; }
private HTMLInputElement GetInputNumberElement(HTMLInputElement enableElement, double initialValue, int widthInDigits, double? step = 1, double? min = 0, double? max = null) { var element = new HTMLInputElement() { Type = InputType.Number, Value = initialValue.ToString(), OnKeyUp = (ev) => { if (ev.IsKeyboardEvent()) { var kev = ev as KeyboardEvent<HTMLInputElement>; if (kev != null) { if (object.Equals(kev["keyCode"], 13)) { ev.PreventDefault(); DrawButton.Click(); } } } } }; if (enableElement != null) { element.Disabled = !enableElement.Checked; var elements = GetElementListToEnable(enableElement); elements.Add(element); } if (step.HasValue) { element.Step = step.ToString(); } if (min.HasValue) { element.Min = min.ToString(); } if (max.HasValue) { element.Max = max.ToString(); } element.Style.Width = widthInDigits + "em"; element.Style.Margin = "5px"; return element; }
public Drawer(Options settings, Mandelbrot calculator) { this.Settings = settings; this.Calculator = calculator; // the actual canvas element var canvas = new HTMLCanvasElement(); canvas.Width = 900; canvas.Height = 500; DrawButton = new HTMLButtonElement { InnerHTML = "Draw the Mandelbrot fractal", OnClick = (ev) => { StartDraw(canvas); } }; DrawButton.SetAttribute("style", "font-size:18px;height: 60px; width:95%; border: 2px solid black; cursor: pointer"); // Iteration controls RadiusElement = GetInputNumberElement(null, this.Settings.MaxRadius, 3, 0.5); IterationCountElement = GetInputNumberElement(null, this.Settings.MaxIterations, 4, 100, 0, 100000); // Color controls ColorMapCheckbox = GetCheckboxElement(this.Settings.UseColorMap); ColorScaleElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorScale, 5, 1000); ColorOffsetElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorOffset, 4, 10); // Julia sets JuliaSetCheckbox = GetCheckboxElement(this.Settings.UseJuliaSet); JuliaImElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Im, 5, 0.005, null); JuliaReElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Re, 5, 0.005, null); // Viewport controls XMinElement = GetInputNumberElement(null, this.Settings.XMin, 5, 0.005, -5.0); XMaxElement = GetInputNumberElement(null, this.Settings.XMax, 5, 0.005, 0.0); YMinElement = GetInputNumberElement(null, this.Settings.YMin, 5, 0.005, -5.0); YMaxElement = GetInputNumberElement(null, this.Settings.YMax, 5, 0.005, 0.0); var paramsColumn = new HTMLTableDataCellElement(); var canvasColumn = new HTMLTableDataCellElement(); paramsColumn.SetAttribute("valign", "top"); canvasColumn.SetAttribute("valign", "top"); canvasColumn.AppendChild(canvas); var layoutRow = new HTMLTableRowElement(); layoutRow.AppendChildren(paramsColumn, canvasColumn); var layout = new HTMLTableElement(); var paramsTable = new HTMLTableElement(); paramsTable.AppendChildren( Row(Label("XMin: "), XMinElement), Row(Label("XMax: "), XMaxElement), Row(Label("YMin: "), YMinElement), Row(Label("YMax: "), YMaxElement), Row(Label("Escape radius: "), RadiusElement), Row(Label("Iteration count: "), IterationCountElement), Row(Label("Use color map: "), ColorMapCheckbox), Row(Label("Color scale: "), ColorScaleElement), Row(Label("Color offset: "), ColorOffsetElement), Row(Label("Use Julia set: "), JuliaSetCheckbox), Row(Label("Im: "), JuliaImElement), Row(Label("Re: "), JuliaReElement), Row(new HTMLHRElement(), 2), Row(DrawButton, 2) ); paramsColumn.AppendChild(paramsTable); layout.AppendChild(layoutRow); Document.Body.AppendChild(layout); }