实际上,点击每个圆圈之后我想要改变它的颜色,例如,我希望它变成红色,总的来说,我想把它当作对照.
我知道如何在双击图片框时绘制代表图表节点的圆圈.我正在使用以下代码:
public Form1()
{
InitializeComponent();
pictureBox1.Paint += new PaintEventHandler(pic_Paint);
}
public Point positionCursor { get; set; }
private List<Point> points = new List<Point>();
public int circleNumber { get; set; }
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
positionCursor = this.PointToClient(new Point(Cursor.Position.X - 25, Cursor.Position.Y - 25));
points.Add(positionCursor);
Label lbl = new Label();
lbl.BackColor = Color.Transparent;
lbl.Font = new Font("Arial", 7);
lbl.Size = new Size(20, 15);
if (circleNumber >= 10)
{
lbl.Location = new Point(points[circleNumber].X + 3, points[circleNumber].Y + 6); …Run Code Online (Sandbox Code Playgroud) 我有一个 winforms 应用程序
这是我的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
Graphics gr;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
gr = this.CreateGraphics();
MyLine myline = new MyLine();
myline.P1 = new Point(100, 0);
myline.P2 = new Point(200, 80);
gr.DrawLine(new Pen(Color.Red), myline.P1,myline.P2);
Rectangle r = new Rectangle(0, 0, 50, 50);
gr.DrawRectangle(new Pen(Color.Teal, 5), r);
if …Run Code Online (Sandbox Code Playgroud) 我想知道如何在C#中绘制矩形并将其拖放到页面中这里我的代码来绘制它但我无法拖放它.
public partial class Form1 : Form
{
public bool drag = false;
int cur_x, cur_y;
Rectangle rec = new Rectangle(10, 10, 100, 100);
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs r)
{
base.OnPaint(r);
Graphics g = r.Graphics;
//g.DrawRectangle(Pens.Black, rec);
g.FillRectangle(Brushes.Aquamarine, rec);
}
private void recmousedown(object sender, MouseEventArgs m)
{
if (m.Button != MouseButtons.Left)
return;
rec = new Rectangle(m.X, m.Y,100,100);
drag = true;
cur_x = m.X;
cur_y = m.Y;
}
private void recmousemove(object sender, MouseEventArgs m)
{
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用撤消和重做功能创建一个简单的绘图应用程序.我假设您可以将您绘制的内容添加到列表中并调用列表来绘制所有内容.然后撤消应该只删除最后添加的项目并重新绘制所有内容.问题是,如何将我绘制的内容添加到列表中并使用该列表进行撤消?
我正在使用位图重绘方法.这是我画的方式:
Point start, end;
bool painting;
private List<PointF> myPoints = new List<PointF>();
private void pnlMain_MouseDown(object sender, MouseEventArgs e)
{
start = e.Location;
painting = true;
}
private void pnlMain_MouseUp(object sender, MouseEventArgs e)
{
painting = false;
}
private void pnlMain_MouseMove(object sender, MouseEventArgs e)
{
if (painting == true)
{
end = e.Location;
g.DrawLine(p, start, end);
myPoints.Add(e.Location);
pnlMain.Refresh();
start = end;
}
}
private void btnUndo_Click(object sender, EventArgs e)
{
g.Clear(cldFill.Color);
if (myPoints.Count > 2)
{
myPoints.RemoveAt(myPoints.Count - 1);
g.DrawCurve(p, …Run Code Online (Sandbox Code Playgroud) 如何在标签周围画一个圆圈?
现在我已经尝试过这个:
public void drawUseCase(int width, int height, UseCase useCase)
{
Label lbUseCase = new Label();
Graphics g = lbUseCase.CreateGraphics();
Pen p = new Pen(Color.Black, 1);
g.DrawEllipse(p, width, height, 200, 200);
lbUseCase.Location = new System.Drawing.Point(width, height);
lbUseCase.Text = useCase.name;
mainPanel.Controls.Add(lbUseCase);
}
Run Code Online (Sandbox Code Playgroud)
但这行不通。有任何想法吗?
它在winforms中。'它不起作用'我的意思是只显示标签,但没有圆圈或其他任何东西。