继承PictureBox的用户控件上显示字符串的问题
我自建了一个继承PictureBox的用户控件,
代码如下:
Public Class ToolButton_ckr
Inherits System.Windows.Forms.PictureBox
#Region " Windows 窗体设计器生成的代码 "
.........
.........
#End Region
Private Sub ToolButton_ckr_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = Me.CreateGraphics
Dim d_titalFont As New Font("宋体", 10, FontStyle.Bold)
g.DrawString("自建控件", d_titalFont, New SolidBrush(Color.Black), 10, 10)
End Sub
End Class
可是在使用这个控件的时候运行时控件上没有出现“自建控件”这几个字,我把这个控件改成继承UserControl,运行时字符串是能正常显示的,可是我这个控件必须要继承PictureBox
哪位能帮我解决一下
问题点数:50、回复次数:7Top
1 楼bitsbird(一瓢 在路上...)回复于 2005-07-22 21:03:26 得分 30
Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
Dim g As System.Drawing.Graphics = pe.Graphics
g.DrawString("自建控件", New Font("Tahoma", 12), New SolidBrush(Color.Red), 10, 10)
End SubTop
2 楼HHLADN(I Want to exceed you)回复于 2005-07-22 21:22:21 得分 0
upTop
3 楼chendazhi(不务正业)回复于 2005-07-22 21:42:58 得分 0
二楼的方法不是一回事吗?Top
4 楼chendazhi(不务正业)回复于 2005-07-23 08:10:09 得分 10
Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
Dim g As System.Drawing.Graphics = pe.Graphics
Dim d_titalFont As New Font("宋体", 10, FontStyle.Bold)
g.DrawString("自建控件", d_titalFont, New SolidBrush(Color.Black), 10, 10)
End SubTop
5 楼chendazhi(不务正业)回复于 2005-07-23 08:17:26 得分 0
有人说说为什么
Private Sub ToolButton_ckr_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = Me.CreateGraphics
Dim d_titalFont As New Font("宋体", 10, FontStyle.Bold)
g.DrawString("自建控件", d_titalFont, New SolidBrush(Color.Black), 10, 10)
End Sub
End Class
不能显示,而
Protected Overloads Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
Dim g As System.Drawing.Graphics = pe.Graphics
Dim d_titalFont As New Font("宋体", 10, FontStyle.Bold)
g.DrawString("自建控件", d_titalFont, New SolidBrush(Color.Black), 10, 10)
End Sub
能显示吗?
Top
6 楼AntingZ(夕惕若)回复于 2005-07-23 08:44:37 得分 10
不要用
Dim g As Graphics = Me.CreateGraphics
应该用
Dim g As Graphics = e.Graphics
@ chendazhi(不务正业-->何苦)
bitsbird(一瓢 闭关)的方法可以,因为用的是pe.Graphics,而不是 Me.CreateGraphics()Top
7 楼wzckr(随意)回复于 2005-07-23 09:12:12 得分 0
谢谢,用e.Graphics解决问题了Top




