textbox -usercontrol problem

A

Agnes

I create my own usercontrol which is [Inherits
System.Windows.Forms.TextBox], my purpose is set all textbox's font into the
same. Now , I can do it by using the following code
Protected Overrides Sub InitLayout()
Me.Font = New System.Drawing.Font("SimSun", 8)
.........
However, during design mode I want to set the font into larger size e.g font
size 9, I can run it sucessfully in the 1st time, if I amend the form during
design mode again, the font size changed back to '8' again,
Please help `~
 
G

Guest

You could shadow the Font property of the base control in the inherited control

Private _Font As Font = New Font("Times", 10, FontStyle.Regular)
Public Shadows Property Font() As Font
Get
Return Me._Font
End Get
Set(ByVal Value As Font)
Me._Font = Value
MyBase.Font = Value
End Set
End Property

Also, override OnCreateControl in your inherited control.

Protected Overrides Sub OnCreateControl()
MyBase.Font = Me.Font
MyBase.OnCreateControl()
End Sub

(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top