星图项目中的帮助 [英] Help in Star Drawing Project

查看:70
本文介绍了星图项目中的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
这是我的项目
我有一个旋转问题.移动和缩放星星.
请帮帮我.
我将此项目开发为:

Hello
This is my project
I have a Problem for Rotation & Move & Scale the Star.
Please Help Me.
I develep this project to:

public Form1()
{
    InitializeComponent();
    this.Paint += new PaintEventHandler(Form1_Paint);
    //System.Drawing.Pen myPen;
    //myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
    //System.Drawing.Graphics formGraphics = this.CreateGraphics();
    //formGraphics.DrawLine(myPen, 0, 0, 200, 200);
}

static void drawFlag(Graphics g)
{
    Point[] star ={
    new Point(0,-60),  new Point(11,-16),
    new Point(58,-16), new Point(18,6),
    new Point(40,41),  new Point(0,18),
    new Point(-40,41), new Point(-18,6),
    new Point(-48,-16),new Point(-11,-16)};
    Point[] starNormal ={
    new Point(0,-50),  new Point(11,-16),
    new Point(48,-16), new Point(18,6),
    new Point(30,41),  new Point(0,18),
    new Point(-30,41), new Point(-18,6),
    new Point(-48,-16),new Point(-11,-16)};
    ////g.FillRectangle(Brushes.Red, 0, 0, 200, 150);
    //g.TranslateTransform(100, 100);
    //g.FillPolygon(Brushes.Blue, star);
    g.TranslateTransform(150, 150);
    g.FillPolygon(Brushes.Blue, star);
    g.FillRectangle(Brushes.Red, 0, 0, 5, 5);
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
    System.Drawing.Graphics graphicsObj;

    graphicsObj = this.CreateGraphics();

    drawFlag(graphicsObj);
    //Pen myPen = new Pen(System.Drawing.Color.Green, 5);
    //Rectangle myRectangle = new Rectangle(20, 20, 250, 200);
    //graphicsObj.DrawEllipse(myPen, myRectangle);
}

private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    if (e.Location.X >= 100 && e.Location.X <= 104)
        MessageBox.Show(e.Location.X.ToString());
}



此图片的网址:
http://bac.freeiz.com/photos/5aa4bd09c07d.png [



this image url :
http://bac.freeiz.com/photos/5aa4bd09c07d.png[^]

推荐答案

第一大我看到的错误是在事件Paint的事件处理程序中创建Graphics的实例.您应该使用事件参数中提供的实例.嗯,设置事件句柄的方式很糟糕;并且没有遵守命名约定.另外,最好重写OnPaint而不是添加处理程序.而且,顺便说一句,无论如何,您都需要通过对System.Windows.Forms.Control进行子类化来使用自定义控件.这样做的第一个原因是使用受保护的SetStyle添加优化的双缓冲,以避免闪烁.

请查看我过去的答案:
在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [
First big mistake I can see is creation of the instance of Graphics in the event handler of the event Paint. You should use the instance provided in the event arguments. Well, the way of setting up event handles is bad; and the naming conventions are not observed. Also, it''s much better to override OnPaint instead of adding the handler. And, by the way, you will need to use the custom control by sub-classing System.Windows.Forms.Control anyway. First reason for that is using protected SetStyle to add optimized double buffering, to avoid flicker.

Please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].



See also my second comment to the question. Do not hard-code immediate constants. Work in a supportable way.



AliRadman问:
AliRadman asked:

我要轮换&移动和Scale Code

I want Rotation & Move & Scale Code

那是什么问题?您可以使用属性System.Drawing.Graphics.Transform或名称中带有单词"Transform"的方法.您将需要RotateTransformScaleTransformTranslateTransform,甚至可能是ResetTransform.请参阅:
http://msdn.microsoft.com/en-us/library/system.drawing. graphics.aspx [^ ].

注释:请不要发布您的问题或评论作为答案.这些帖子将被删除;没有人收到电子邮件通知.

—SA

So, what''s the problem? You can use the property System.Drawing.Graphics.Transform or the methods having the word "Transform" in their names. You would need RotateTransform, ScaleTransform, TranslateTransform and maybe ResetTransform. Please see:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

A note: Please, don''t post your questions or comments as answers. Such posts will be deleted; no one gets e-mail notifications.

—SA


这篇关于星图项目中的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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