在编辑控件中绘制形状 [英] Drawing shapes in an edit control

查看:62
本文介绍了在编辑控件中绘制形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个将输入作为文本的编辑控件.但是如何在其上绘制用户定义的形状.

请帮忙.

Hi,
I have an edit control which takes input as text. But how to draw user defined shapes onto it.

Please help.

推荐答案

从CEdit派生自定义控件,然后实现OnPaint

您将获得类似于以下内容的内容,您将在其中使用绘画dc绘制形状...

Derive a custom control from a CEdit and then implement OnPaint

You''ll get something like the following where you will use your paint dc for drawing shapes...

class CShapeEdit : public CEdit
{
    DECLARE_DYNAMIC(CShapeEdit)

public:
    CShapeEdit();
    virtual ~CShapeEdit();

protected:
    DECLARE_MESSAGE_MAP()
    afx_msg void OnPaint();
};

BEGIN_MESSAGE_MAP(CShapeEdit, CEdit)
    ON_WM_PAINT()
END_MESSAGE_MAP()

IMPLEMENT_DYNAMIC(CShapeEdit, CEdit)

CShapeEdit::CShapeEdit()
{
}

CShapeEdit::~CShapeEdit()
{
}

void CShapeEdit::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CEdit::OnPaint() for painting messages
}



现在,在承载自定义编辑控件的对话框类中,添加一个成员变量



Now in your dialog class, which hosts the custom edit control, you add a member variable

CShapeEdit m_ShapeEdit;



在对话框类的实现中,使用DDX将其绑定到UI



In the implementation of your dialog class bind it to the UI using DDX

DDX_Control(pDX, IDC_SHAPE_EDIT, m_ShapeEdit);



然后稍后使它使用
重绘自身



Then later on cause it to redraw itself with

m_ShapeEdit.RedrawWindow();



现在,您可以使用画布来浏览Win32 GDI !!!!!



Now you have a canvas with which to explore the Win32 GDI!!!!


如果仅在控件的某些左侧和/或右侧部分绘制就足够了,
您可以使用CYourEdit::SetMargins(uiLeftUntouchedPixels, uiRightUntouchedPixels)
以防止在其中出现CEdit -content画图,即使在编辑尖号模式下也是如此.
然后,您还可以在创建时或创建后将WS_CLIPCHILDREN样式添加到CYourEdit控件
并将一些所有者绘制的CYourShapeStatic子控件放在已释放"区域:)

If it is enough to draw only on the some left and/or right parts of the control,
you could use CYour:SetMargins(uiLeftUntouchedPixels, uiRightUntouchedPixels)
to prevent the CEdit-content painting there, even in the edit-caret mode.
Then you could also add(at or after the creating) the WS_CLIPCHILDREN style to CYourEdit control
and place some owner-drawn CYourShapeStatic child-control(s) onto the "freed" area(s) :)

Zerr0cool写道:
Zerr0cool wrote:

我想在用户输入内容的Edit控件中绘制矩形和圆形.

I want to draw rectangles, circles in the Edit control where the user types in.


尝试在此处所示的透明模式下设置控件. [


Try to set your control in the transparent mode as shown here[^]
and then to draw the shapes on the parent''s surface, "behind" the control :)


这篇关于在编辑控件中绘制形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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