在c#中的页面中间创建一个圆圈
Creating a circle in the middle of a page in c#
我需要帮助在页面中间创建一个圆圈。该页面完全空白,没有任何内容 - 没有 div 或任何东西。我在互联网上搜索了答案并找到了很多 但是 它们似乎没有出现在屏幕上。该页面保持空白。
我找到的很多代码都可以工作,但我不知道要将什么添加到 HTML 文件中,所以会出现圆圈。该页面是一个基本的 Visual Studio ASP.NET 项目,如果有帮助的话。
如果有人能够提供 C# 代码,我将不胜感激,但是,如果有人能告诉我如何 HTML 使其实际显示在页面上,我将欣喜若狂。
编辑:我没有 post 代码的唯一原因是因为我尝试了很多选项但 none 有效,所以我不知道要 post 哪个.
这是我决定放在这里的代码,因为它看起来最容易工作:
public static class GraphicsExtensions
{
public static void DrawCircle(this Graphics g, Pen pen,
float centerX, float centerY, float radius)
{
g.DrawEllipse(pen, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
public static void FillCircle(this Graphics g, Brush brush,
float centerX, float centerY, float radius)
{
g.FillEllipse(brush, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
}
我只是不确定我是否应该把它放在一个空的 C# 文件中 link 它到 HTML 或者是否应该将它添加到 'Default.aspx.cs (or even the "Global.asax.cs")' 文件并喜欢HTML 使用某种形式。
EDIT2:感谢您的帮助!我目前停留在如何获取代码以在 canvas 中绘制圆圈并为其着色。我有这段代码来获取元素:
System.Windows.Forms.WebBrowser webBrowser = null;
HtmlElement circle;
HtmlDocument document = webBrowser.Document;
circle = document.GetElementById("circlecanvas");
但我如何在 canvas 中画一个圆圈并给它上色。到目前为止,我已经尝试了很多这样的东西:
Graphics graphics = null;
Pen pen = null;
Brush brush = null;
Rectangle rectangle = new Rectangle();
rectangle.X = circle.ClientRectangle.X;
rectangle.Y = circle.ClientRectangle.Y;
graphics.DrawRectangle(pen, rectangle);
e.Graphics.FillRectangle(brush, rectangle);
还 none 工作。那有可能吗?
谢谢,
梦想
存在一些可能性
我假设您使用的是某种来自 C# 的 Web 框架,但此答案适用于所有框架。
您可以使用 canvas 画一个圆。
Drawing circles with canvas
您可以使用 CSS
如果您给 div 边框半径等于其宽度和高度的 50%,它将是圆形的。
How to draw circle in html page?
我需要帮助在页面中间创建一个圆圈。该页面完全空白,没有任何内容 - 没有 div 或任何东西。我在互联网上搜索了答案并找到了很多 但是 它们似乎没有出现在屏幕上。该页面保持空白。
我找到的很多代码都可以工作,但我不知道要将什么添加到 HTML 文件中,所以会出现圆圈。该页面是一个基本的 Visual Studio ASP.NET 项目,如果有帮助的话。
如果有人能够提供 C# 代码,我将不胜感激,但是,如果有人能告诉我如何 HTML 使其实际显示在页面上,我将欣喜若狂。
编辑:我没有 post 代码的唯一原因是因为我尝试了很多选项但 none 有效,所以我不知道要 post 哪个. 这是我决定放在这里的代码,因为它看起来最容易工作:
public static class GraphicsExtensions
{
public static void DrawCircle(this Graphics g, Pen pen,
float centerX, float centerY, float radius)
{
g.DrawEllipse(pen, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
public static void FillCircle(this Graphics g, Brush brush,
float centerX, float centerY, float radius)
{
g.FillEllipse(brush, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
}
我只是不确定我是否应该把它放在一个空的 C# 文件中 link 它到 HTML 或者是否应该将它添加到 'Default.aspx.cs (or even the "Global.asax.cs")' 文件并喜欢HTML 使用某种形式。
EDIT2:感谢您的帮助!我目前停留在如何获取代码以在 canvas 中绘制圆圈并为其着色。我有这段代码来获取元素:
System.Windows.Forms.WebBrowser webBrowser = null;
HtmlElement circle;
HtmlDocument document = webBrowser.Document;
circle = document.GetElementById("circlecanvas");
但我如何在 canvas 中画一个圆圈并给它上色。到目前为止,我已经尝试了很多这样的东西:
Graphics graphics = null;
Pen pen = null;
Brush brush = null;
Rectangle rectangle = new Rectangle();
rectangle.X = circle.ClientRectangle.X;
rectangle.Y = circle.ClientRectangle.Y;
graphics.DrawRectangle(pen, rectangle);
e.Graphics.FillRectangle(brush, rectangle);
还 none 工作。那有可能吗?
谢谢, 梦想
存在一些可能性
我假设您使用的是某种来自 C# 的 Web 框架,但此答案适用于所有框架。
您可以使用 canvas 画一个圆。
Drawing circles with canvas
您可以使用 CSS
如果您给 div 边框半径等于其宽度和高度的 50%,它将是圆形的。 How to draw circle in html page?