Last active
October 6, 2020 20:49
-
-
Save Viklor/8981f48902d0f1854857fb69605becf8 to your computer and use it in GitHub Desktop.
Rectangle ratio calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using NGettext; | |
using R7.Webmate.Xwt.Icons; | |
using R7.Webmate.Xwt.Text; | |
using Xwt; | |
namespace R7.Webmate.Xwt | |
{ | |
public class HelloWorldWidget : Widget | |
{ | |
protected ICatalog T = TextCatalogKeeper.GetDefault(); | |
protected TextEntry txtWidth; | |
protected TextEntry txtHeight; | |
protected TextEntry txtCalculed; | |
public HelloWorldWidget() | |
{ | |
var vbox = new VBox(); | |
var lblWidth = new Label(T.GetString("Ширина:")); | |
var lblHeight = new Label(T.GetString("Высота:")); | |
var btnCalculed = new Button(T.GetString("Calculate")); | |
txtWidth = new TextEntry(); | |
txtHeight = new TextEntry(); | |
txtCalculed = new TextEntry(); | |
btnCalculed.Clicked += btnCalculed_Clicked; | |
vbox.PackStart(lblWidth, false, true); | |
vbox.PackStart(txtWidth, false, true); | |
vbox.PackStart(lblHeight, false, true); | |
vbox.PackStart(txtHeight, false, true); | |
vbox.PackStart(btnCalculed, false, true); | |
vbox.PackStart(txtCalculed, false, true); | |
vbox.Margin = Const.VBOX_MARGIN; | |
Content = vbox; | |
Content.Show(); | |
} | |
static int GCD(int a, int b) | |
{ | |
while (b != 0) | |
{ | |
var t = b; | |
b = a % b; | |
a = t; | |
} | |
return a; | |
} | |
void btnCalculed_Clicked(object sender, EventArgs e) | |
{ | |
var w = int.Parse(txtWidth.Text); | |
var h = int.Parse(txtHeight.Text); | |
var a = w; | |
var b = h; | |
var r = (w / GCD(a, b) + ":" + h / GCD(a, b)) ; | |
txtCalculed.Text = r.ToString(); | |
} | |
} | |
} |
var w = int.Parse (txtWidth.Text);
var h = int.Parse (txtHeight.Text);
var r = (float) w / h;
txtCalculed.Text = r.ToString ();
namespace R7.Webmate.Xwt
{
public class HelloWorldWidget : Widget
{
protected ICatalog T = TextCatalogKeeper.GetDefault ();
protected TextEntry txtWidth;
protected TextEntry txtHeight;
protected TextEntry txtCalculed;
public HelloWorldWidget()
{
var vbox = new VBox ();
var lblWidth = new Label (T.GetString ("Ширина:"));
var lblHeight = new Label(T.GetString("Высота:"));
var btnCalculed = new Button (T.GetString ("Click me!"));
txtWidth = new TextEntry ();
txtHeight = new TextEntry();
txtCalculed = new TextEntry ();
var w = int.Parse(txtWidth.Text);
var h = int.Parse(txtHeight.Text);
var r = (float) w / h;
btnCalculed.Clicked += btnCalculed_Clicked;
vbox.PackStart (lblWidth, false, true);
vbox.PackStart (txtWidth, false, true);
vbox.PackStart(lblHeight, false, true);
vbox.PackStart(txtHeight, false, true);
vbox.PackStart (btnCalculed, false, true);
vbox.PackStart (txtCalculed, false, true);
vbox.Margin = Const.VBOX_MARGIN;
Content = vbox;
Content.Show ();
}
void btnCalculed_Clicked(object sender, EventArgs e)
{
txtCalculed.Text = r.ToString ();
}
}
Basic error: "Имя "r" не существует в данном контексте". Because of this, the program cannot start.
var w = int.Parse (txtWidth.Text);
var h = int.Parse (txtHeight.Text);
var r = (float) w / h;
txtCalculed.Text = r.ToString ();
А первые три строчки? Видимо, невидимые чернила...
И не нужно дублировать весь код в комментариях - обновляете сам gist, там есть история версий (revisions) - см. мой форк.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rename the file to
HelloWorldWidget.cs