创建可通过上下文菜单栏选择的图形对象线

编程入门 行业动态 更新时间:2024-10-27 14:24:21
本文介绍了创建可通过上下文菜单栏选择的图形对象线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个应用程序,用户可以选择他/她绘制的线条.他/她还可以右键单击它,然后会弹出一个上下文菜单栏.有任何想法吗? 问候:-D

解决方案

做到这一点的方法是将行的位置存储在代码中,并随着鼠标的移动检查其是否过线.如果要绘制多个对象,则代码中将包含一组对象,您的paint方法将绘制它们,并且您的鼠标移动代码将在它们上迭代,以查看您的鼠标是否在触摸.

在这里,我设法使用一个硬编码矩形来做到这一点.

<pre lang="cs"> private bool selectGraph = false; private Rectangle myrec = new Rectangle(50, 50, 100, 100); private Graphics g; private void panel1_Paint(object sender, PaintEventArgs e) { g = panel1.CreateGraphics(); SolidBrush sb = new SolidBrush(Color.Blue); Pen p = new Pen(Color.Blue, 5); g.DrawRectangle(p, myrec); g.FillRectangle(sb, myrec); } private void panel1_MouseUp(object sender, MouseEventArgs e) { Point mPT = new Point(e.X, e.Y); if (e.Button == MouseButtons.Left) { if (myrec.Contains(mPT)) { selectGraph = true; button1.Enabled = true; } else { selectGraph = false; button1.Enabled = false; } } Invalidate(); }

但是我想要的是运行时绘制线. :doh:

问题已解决.使用Microsoft VisualBasic PowerPack 3.0:笑:

I''m creating an application which the user is able to select the line he/she draw. He/She can also right click it and a context menu strip will pop out. Any Ideas? Regards :-D

解决方案

The way to do this is to store the position of the line in your code, and as the mouse moves, check if it''s crossing the line. If you want to draw more than one object, you''d have a collection of objects in your code, your paint method would draw them and your mouse move code would iterate over them to see if your mouse was touching one.

Here I managed to do it using a hard coded rectangle.

<pre lang="cs"> private bool selectGraph = false; private Rectangle myrec = new Rectangle(50, 50, 100, 100); private Graphics g; private void panel1_Paint(object sender, PaintEventArgs e) { g = panel1.CreateGraphics(); SolidBrush sb = new SolidBrush(Color.Blue); Pen p = new Pen(Color.Blue, 5); g.DrawRectangle(p, myrec); g.FillRectangle(sb, myrec); } private void panel1_MouseUp(object sender, MouseEventArgs e) { Point mPT = new Point(e.X, e.Y); if (e.Button == MouseButtons.Left) { if (myrec.Contains(mPT)) { selectGraph = true; button1.Enabled = true; } else { selectGraph = false; button1.Enabled = false; } } Invalidate(); }

But what I want is a runtime draw line. :doh:

Problem Solved. Use Microsoft VisualBasic PowerPack 3.0 :laugh:

更多推荐

创建可通过上下文菜单栏选择的图形对象线

本文发布于:2023-11-23 02:22:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   可通过   菜单栏   图形   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!