无法重绘绘制区域? [英] Could not repaint the drawn area?

查看:68
本文介绍了无法重绘绘制区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个用户控件添加到主窗体。

1.UserControl1 - 从UserControl2获取输入并使用drawString显示消息

2.UserControl2有TextBox,用户可以在其上输入文本,导致UserControl1显示用户输入的文本

PaintEvent已在UserControl1中注册。

Upadate,refresh和invalidate无法重绘用户输入的文本



[edit]

I have 2 user control added to the main form.
1.UserControl1 -Take Input from UserControl2 and display message by using drawString
2.UserControl2 have TextBox,User can enter the text on it causes UserControl1 to display user entered text
PaintEvent is registered with UserControl1.
Upadate ,refresh and invalidate could not redraw the user entered text

[edit]

// UserControl1
{
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        _titleText = textBox1.Text;
        _mainform = new MainForm();
        this.titleChanged += new TitleChangedHAndler(_mainform.onTitleChanged);
        if (titleChanged != null)
        {
            titleChanged(_titleText);
        }
    }     
}

// MainForm
    public void onTitleChanged(string strText)
    {
       UserControl2.setText(strText);
       ;
    }

// UserControl2
    private void paint(object sender, PaintEventArgs e)
    {
        drawString(Text,...);
    }
    public void setText(theText)
    {
        Text = theText;
        this.Invalidate();
        this.Update();
    }
}



[/ edit]


[/edit]

推荐答案

你的
paint 

方法只是私有方法。除非您在代码中专门进行调用,否则永远不会调用它。您需要覆盖OnPaint并将绘制代码放在那里。它将通过Invalidate来实现。





method is just private method. It will never be called unless you cal it specifically in your code. You need to override OnPaint and place your painting code there. It will be trigerred by on Invalidate.


protected override void OnPaint(PaintEventArgs e)
{

    //Add your painting code  here
    base.OnPaint(e);
}


这篇关于无法重绘绘制区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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