本文整理汇总了C#中Canvas.Get2DContext方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.Get2DContext方法的具体用法?C# Canvas.Get2DContext怎么用?C# Canvas.Get2DContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.Get2DContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var w = 800;
var h = 600;
// create a new Canvas
var canvas = new Canvas();
canvas.Width = w;
canvas.Height = h;
// add canvas to the div with id = "target" (defined in MainPage.html)
Element.GetById("target").AppendChild(canvas);
// get the 2D context for the canvas, which contains all the draw methods
var context = canvas.Get2DContext();
// draw background rect
context.FillStyle = new RgbStyle(0xcc, 0x66, 0x99);
context.FillRect(0, 0, w, h);
context.LineWidth = 2;
// draw flowers
context.StrokeStyle = new RgbStyle(0x33, 0x33, 0x33);
context.FillStyle = new RgbStyle(0xff, 0xff, 0);
DrawFlower(context, Math.Min(w, h) * 0.4, 25d, 0.5 * w, 0.5 * h);
context.FillStyle = new RgbStyle(0xff, 0x0, 0);
DrawFlower(context, Math.Min(w, h) * 0.1, 12d, 0.5 * w, 0.5 * h);
}
示例2: Main
public static void Main()
{
var w = 800;
var h = 600;
// create a new Canvas
var canvas = new Canvas();
canvas.Width = w;
canvas.Height = h;
// add canvas to the div with id = "target" (defined in MainPage.html)
var target = Element.GetById("target");
target.AppendChild(canvas);
// get the 2D context for the canvas, which contains all the draw methods
var context = canvas.Get2DContext();
var angleOffset = 0d;
var timer = new IntervalDispatcher(TimeSpan.FromMilliseconds(30));
timer.Tick += (s, e) =>
{
// draw background rect
context.FillStyle = new RgbStyle(0xcc, 0x66, 0x99);
context.FillRect(0, 0, w, h);
context.LineWidth = 2;
// draw flowers
context.StrokeStyle = new RgbStyle(0x33, 0x33, 0x33);
context.FillStyle = new RgbStyle(0xff, 0xff, 0);
DrawFlower(context, Math.Min(w, h) * 0.4, 25d, 0.5 * w, 0.5 * h, angleOffset);
context.FillStyle = new RgbStyle(0xff, 0x0, 0);
DrawFlower(context, Math.Min(w, h) * 0.1, 12d, 0.5 * w, 0.5 * h, angleOffset);
angleOffset += 0.02;
};
timer.Start();
bool started = true;
var startButton = new Element("button") { TextContent = "Start" };
var stopButton = new Element("button") { TextContent = "Stop" };
startButton.Click += (s, e) => {
timer.Start();
started = true;
startButton.Enabled = !started;
stopButton.Enabled = started;
};
stopButton.Click += (s, e) => {
timer.Stop();
started = false;
startButton.Enabled = !started;
stopButton.Enabled = started;
};
startButton.Enabled = !started;
stopButton.Enabled = started;
target.AppendChild(startButton);
target.AppendChild(stopButton);
}