不理解控件中的OnPaint [英] Not understanding OnPaint in a control

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

问题描述

大家好,


我试图在自定义文本框中覆盖OnPaint

控件(所以我可以抽取字幕等等)。在下面的

代码中,我得到了绘制表单。消息为

预期,但不是绘制控件。它也没有影响显式调用txtTest.Invalidate或

txtTest.Refresh。我在这里错过了一些简单的东西吗?

任何正确方向的推动都会受到赞赏。


BB


公开Class Form1

继承System.Windows.Forms.Form


#Region" Windows窗体设计器生成的代码

#End Region


Private Sub Form1_Load(ByVal sender As System.Object,

ByVal e As System.EventArgs)处理MyBase.Load

Dim txtTest作为新的MyTextBox

Controls.Add(txtTest)

End Sub


受保护覆盖​​Sub onpaint(ByVal e As

PaintEventArgs)

MessageBox.Show("绘制表单...)

结束子


结束班


公共类MyTextBox

继承TextBox


受保护覆盖​​Sub onpaint(ByVal e As

PaintEventArgs)

MessageBox.Show("绘制文本框......) ;)

结束子


结束班

解决方案

*BB <一个******* @ discussions.microsoft.com> scripsit:

我试图在自定义文本框
控件中覆盖OnPaint(所以我可以抽取字幕等等)。在下面的
代码中,我得到了绘制表单。消息为
预期,但不是绘制控件。它还




在''Form1'的处理程序中调用''MyBase.OnPaint(e)''。


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>


发布您的代码。 。 。


BB写道:

大家好,

我试图在自定义文本框中覆盖OnPaint <控制(所以我可以抽取标题等)。在下面的
代码中,我得到了绘制表单。消息为
预期,但不是绘制控件。它也没有效果显式调用txtTest.Invalidate或
txtTest.Refresh。我在这里错过了一些简单的东西吗?
任何正确方向的推动都会受到赞赏。

BB

公共类Form1
继承System.Windows.Forms .Form

#Region" Windows窗体设计器生成的代码
#End Region
私有Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs)处理MyBase.Load
Dim txtTest作为新的MyTextBox
Controls.Add(txtTest)
End Sub

受保护的覆盖Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox .Show(绘制形式......)
结束子

结束类

公共类MyTextBox
继承TextBox
受保护的覆盖Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("绘制文本框......)
End Sub




问候 - OHM#开* *********@BTInternet.com


这是因为文本框没有调用OnPaint事件。 />

" BB" <一个******* @ discussions.microsoft.com>在消息中写道

news:0b **************************** @ phx.gbl ... < blockquote class =post_quotes>大家好,

我试图在自定义文本框中控制OnPaint
控件(所以我可以抽取字幕等等)。在下面的
代码中,我得到了绘制表单。消息为
预期,但不是绘制控件。它也没有效果显式调用txtTest.Invalidate或
txtTest.Refresh。我在这里错过了一些简单的东西吗?
任何正确方向的推动都会受到赞赏。

BB

公共类Form1
继承System.Windows.Forms .Form

#Region" Windows窗体设计器生成的代码
#End Region
私有Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs)处理MyBase.Load
Dim txtTest作为新的MyTextBox
Controls.Add(txtTest)
End Sub

受保护的覆盖Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox .Show(绘制形式......)
结束子

结束类

公共类MyTextBox
继承TextBox
受保护的覆盖Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("绘制文本框......)
End Sub

结束类



Hello all,

I am trying to override OnPaint in a custom textbox
control (so I can drawstring a caption, etc.). In the
code below, I get the "painting the form" message as
expected, but not the "painting the control". It also
has no effect to explicitly call txtTest.Invalidate or
txtTest.Refresh. Am I missing something simple here?
Any push in the right direction is appreciated.

BB

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtTest As New MyTextBox
Controls.Add(txtTest)
End Sub

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the form...")
End Sub

End Class

Public Class MyTextBox
Inherits TextBox

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the textbox...")
End Sub

End Class

解决方案

* "BB" <an*******@discussions.microsoft.com> scripsit:

I am trying to override OnPaint in a custom textbox
control (so I can drawstring a caption, etc.). In the
code below, I get the "painting the form" message as
expected, but not the "painting the control". It also



Call ''MyBase.OnPaint(e)'' in the handler on ''Form1''.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Post your code . . .


BB wrote:

Hello all,

I am trying to override OnPaint in a custom textbox
control (so I can drawstring a caption, etc.). In the
code below, I get the "painting the form" message as
expected, but not the "painting the control". It also
has no effect to explicitly call txtTest.Invalidate or
txtTest.Refresh. Am I missing something simple here?
Any push in the right direction is appreciated.

BB

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtTest As New MyTextBox
Controls.Add(txtTest)
End Sub

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the form...")
End Sub

End Class

Public Class MyTextBox
Inherits TextBox

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the textbox...")
End Sub

End Class



Regards - OHM# On**********@BTInternet.com


It''s because the Textbox doesn''t call the OnPaint Event.

"BB" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...

Hello all,

I am trying to override OnPaint in a custom textbox
control (so I can drawstring a caption, etc.). In the
code below, I get the "painting the form" message as
expected, but not the "painting the control". It also
has no effect to explicitly call txtTest.Invalidate or
txtTest.Refresh. Am I missing something simple here?
Any push in the right direction is appreciated.

BB

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtTest As New MyTextBox
Controls.Add(txtTest)
End Sub

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the form...")
End Sub

End Class

Public Class MyTextBox
Inherits TextBox

Protected Overrides Sub onpaint(ByVal e As
PaintEventArgs)
MessageBox.Show("Painting the textbox...")
End Sub

End Class



这篇关于不理解控件中的OnPaint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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