本文介绍了使用C Sharp的动态图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在做一个需要在其中创建视觉动态点的项目.要求当我单击该点时,它会从一个简单的矩形点变成一个填充的矩形点,并且当我拖动它时,它必须动态更改其位置.我必须使用C Sharp严格执行所有这些操作.我不能使用WPF.目前,我正在使用Windows.System.Drawing实用程序,但我不知道如何进一步.请帮我.任何支持将不胜感激.
谢谢

Hello Friends,
I am working on a project where in I need to create a visual dynamic point. It is required that when I click on the point it turns from a simple rectangular point to a filled rectangular point and when I drag it, it changes its position dynamically. I am required to do all this strictly in C sharp. I cannot use WPF. Currently I am using Windows.System.Drawing utility but I don''t know how to move further. Please help me. Any support will be appreciated.
Thank You

推荐答案

//--------------------------------------------------------------------------------
protected override void OnMouseDown(MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left && m_weapon != null)
    {
        m_moving = true;
    }
    base.OnMouseDown(e);
}

//--------------------------------------------------------------------------------
protected override void OnMouseEnter(EventArgs e)
{
    if (m_weapon != null)
    {
        Cursor = Cursors.SizeAll;
    }
    base.OnMouseEnter(e);
}

//--------------------------------------------------------------------------------
protected override void OnMouseLeave(EventArgs e)
{
    Cursor = Cursors.Default;
    base.OnMouseLeave(e);
}

//--------------------------------------------------------------------------------
protected override void OnMouseUp(MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        m_moving = false;
    }
    base.OnMouseUp(e);
}

//--------------------------------------------------------------------------------
protected override void OnMouseMove(MouseEventArgs e)
{
    if (m_moving)
    {
        m_origin.X = e.Location.X - m_offset.X;
        m_origin.Y = e.Location.Y - m_offset.Y;
        m_bmpRect.X = m_origin.X;
        m_bmpRect.Y = m_origin.Y;
        Refresh();
    }
    else
    {
        m_offset.X = e.Location.X - m_bmpRect.X;
        m_offset.Y = e.Location.Y - m_bmpRect.Y;
    }
    base.OnMouseMove(e);
}



适用的油漆处理程序代码如下所示:



The applicable paint hander code looks like this:

//--------------------------------------------------------------------------------
protected override void OnPaint(PaintEventArgs e)
{
    Rectangle imgRect = new Rectangle(m_origin.X, m_origin.Y, m_weapon.Width, m_weapon.Height);
    e.Graphics.DrawImage(m_weapon, imgRect, 0, 0, m_weapon.Width, m_weapon.Height, GraphicsUnit.Pixel, imageAttributes);
    base.OnPaint(e);
}



顺便说一句,Google是一个很好的资源.



Google is a great resource, btw.



这篇关于使用C Sharp的动态图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:45
查看更多