如何创建不同的形状并填充其中的颜色? [英] How to create different shapes and fill color in them?

查看:81
本文介绍了如何创建不同的形状并填充其中的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个表单,表单上有一个圆圈,在这个圆圈内我想添加不同的形状(用户定义),然后用不同的颜色填充这些形状。



有时形状都是圆形,有时没有指定的形状



我该怎么做?

解决方案

我希望这个提示可以帮到你:没有没有指定的形状。所有不是基元的形状通常使用大多数现代图形API中可用的 polygon Bezier曲线的概念建模。请参阅:

http://en.wikipedia.org/wiki/Besier_curve [< a href =http://en.wikipedia.org/wiki/Besier_curvetarget =_ blanktitle =New Window> ^ ];

如果您正在使用 System.Windows.Forms ,您可以使用 System.Drawing ,特别是:

http://msdn.microsoft.com/en-us/library/dd0c4s09 (v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/07e699tw(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/l ibrary / 0df9swbe(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/7t4azb96(v = vs.110).aspx [ ^ ],

< a href =http://msdn.microsoft.com/en-us/library/ms142097(v=vs.110).aspx> http://msdn.microsoft.com/en-us/library/ms142097( v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/89sks199(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/a7h66bsy(v=vs.110).aspx [ ^ ],

http:// msdn .microsoft.com / zh-cn / library / cbw3w13d(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/zy3kce13(v = vs.110)的.aspx [< a href =http://msdn.microsoft.com/en-us/library/zy3kce13(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com /en-us/library/ds101091(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/bs29b5k0(v = vs.110).aspx [ ^ ]。



-SA


Yellow_Flash写道:

这是我想要创建的图纸之一

但是每次圆形尺寸和颜色都应该改变但是每次都是相同的图纸



如果我想在圆圈中添加一些其他形状,那么我不知道这样做吗?

你需要的是动画。您可以使用图形的一些数据模型以及从数据到渲染的渲染过程,使用您显示的函数,从重写的 OnPaint 调用或事件的处理程序绘制中某些控件的渲染位置。那么你应该有一些线程在数据模型上做动画。此线程应使用 Control.Invoke 通知UI线程,并且调用的方法应使用一个或多个控件在每次更改时刷新图形.Invalidate 方法。请查看我过去的答案:



如何加快我的vb.net应用程序? [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



你可以使用在所有情况下,当图形更改时,此技术;不仅适用于动画,还适用于任何不断变化的行为:互动,动画,组合,随时间变化的任何其他活动。



-SA


这是我想要创建的图纸之一

但是每次圆形尺寸和颜色都应该改变但是在这里每个都是相同的图纸时间



如果我想在圆圈中添加其他形状,那么我不知道这样做吗?





 私人  Sub  DrawCircle()
Dim g As Graphics
g = Panel1.CreateGraphics
Dim yellowPen 作为 笔(Color.Yellow, 20
Dim bluePen As 笔(Color.Blue, 30
< span class =code-keyword> Dim greenPen As 笔(Color.Green) , 20
Dim skybluePen As 笔(Color.AliceBlue, 20
Dim voiletPen 作为 笔(Color.Violet, 15
Dim blackPen As 笔(Color.Black, 2

' 绘制省略号
g.DrawEllipse(yellowPen, 260 180 10 10

g.DrawEllipse(greenPen, 240 160 50 50

g.DrawEllipse(bluePen, 220 140 90 90

g.DrawEllipse(greenPen, 200 120 130 130

g.DrawEllipse(skybluePen, 180 100 170 170

g.DrawEllipse(blackPen, 180 100 170 170

g.DrawEllipse(voiletPen, 170 90 190 190


结束 Sub

私人 Sub Panel1_Paint( ByVal sender As 对象 ByVal e As System.Windows.Forms .PaintEventArgs)句柄 Panel1.Paint
DrawCircle()
结束


I am creating a form on which there is a circle on the form and inside this circle i want to add different shapes(user defined) and then fill those shapes with different colors.

Some times the shapes are all circles and some times there are not specified shapes

How can i do this?

解决方案

I hope this hint can help you: there are not "not specified shapes". All the shapes which are not the primitives are usually modeled using the concept of polygon and Bezier curve available in most modern graphics APIs. Please see:
http://en.wikipedia.org/wiki/Besier_curve[^];
if you are working with System.Windows.Forms, you can use System.Drawing, in particular:
http://msdn.microsoft.com/en-us/library/dd0c4s09(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/07e699tw(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0df9swbe(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/7t4azb96(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/ms142097(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/89sks199(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/a7h66bsy(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/cbw3w13d(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/zy3kce13(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/ds101091(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/bs29b5k0(v=vs.110).aspx[^].

—SA


Yellow_Flash wrote:

Here is one of the drawing I wanted to create
But every time circle size and color should be changed but in this it is a same drawing every time

And if i want to add some other shapes in the circle then i don't have any idea to do so?

What you need is animation. You can use some data model of your graphics and the rendering procedure from data to rendering using the functions you show, called from overridden OnPaint or a handler of the event Paint of some control where you render it. Then you should have some thread doing animation on the data model. This thread should notify the UI thread using Control.Invoke, and invoked method should cause refresh of the graphics in each change using one or more of the Control.Invalidate methods. Please see my past answers:

How to speed up my vb.net application?[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

You can use this technique in all cases when you graphics changes; not only for animation, but for any changing behavior: interactive, animated, combination of those, changing with time by any other events.

—SA


Here is one of the drawing I wanted to create
But every time circle size and color should be changed but in this it is a same drawing every time

And if i want to add some other shapes in the circle then i don't have any idea to do so?


Private Sub DrawCircle()
Dim g As Graphics
g = Panel1.CreateGraphics
Dim yellowPen As New Pen(Color.Yellow, 20)
Dim bluePen As New Pen(Color.Blue, 30)
Dim greenPen As New Pen(Color.Green, 20)
Dim skybluePen As New Pen(Color.AliceBlue, 20)
Dim voiletPen As New Pen(Color.Violet, 15)
Dim blackPen As New Pen(Color.Black, 2)

' Draw ellipses
g.DrawEllipse(yellowPen, 260, 180, 10, 10)

g.DrawEllipse(greenPen, 240, 160, 50, 50)

g.DrawEllipse(bluePen, 220, 140, 90, 90)

g.DrawEllipse(greenPen, 200, 120, 130, 130)

g.DrawEllipse(skybluePen, 180, 100, 170, 170)

g.DrawEllipse(blackPen, 180, 100, 170, 170)

g.DrawEllipse(voiletPen, 170, 90, 190, 190)


End Sub

 Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
DrawCircle()
End Sub


这篇关于如何创建不同的形状并填充其中的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆