|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Rewriting the TextboxOk, here's another of my fun questions. I want to rewrite the textbox control in VB.NET. I need to implement superscript and subscript within the box. Don't ask why, but I can't use RTF as my superscript and subscript's are always numbers and are defined as specific characters. ie. char(192) = superscript 1 Does anyone know how to inherit and change the onPaint method of the textbox? I have created my own controlt o try and do this but apparently the onPaint method is never called: Public Class SuperTextBox Inherits TextBox Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim sf As New StringFormat sf.LineAlignment = StringAlignment.Center e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), e.ClipRectangle) Dim strToPrint As String = Me.Text Dim boundLeft As Integer = e.ClipRectangle.Left For i As Integer = 0 To strToPrint.Length - 1 If clsSuperScriptHandler.isSubScript(CChar(strToPrint.Substring(i, 1))) Then 'subscript Dim f As New Font(me.Font.FontFamily, _ me.Font.Size - 3, _ Me.Font.Style, _ Me.Font.Unit) e.Graphics.DrawString(strToPrint.Substring(i, 1), f, _ New SolidBrush(Me.ForeColor), New RectangleF(boundLeft, e.ClipRectangle.Y + 5, e.ClipRectangle.Width, e.ClipRectangle.Height), sf) boundLeft += CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), f).Width * 0.7) ElseIf clsSuperScriptHandler.isSuperScript(CChar(strToPrint.Substring(i, 1))) Then 'superscript Dim f As New Font(Me.Font.FontFamily, _ Me.Font.Size - 3, _ Me.Font.Style, _ Me.Font.Unit) e.Graphics.DrawString(strToPrint.Substring(i, 1), f, _ New SolidBrush(Me.ForeColor), New RectangleF(boundLeft, e.ClipRectangle.Y - 5, e.ClipRectangle.Width, e.ClipRectangle.Height), sf) boundLeft += CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), f).Width * 0.7) Else 'normal script e.Graphics.DrawString(strToPrint.Substring(i, 1), Me.Font, _ New SolidBrush(Me.ForeColor), New RectangleF(boundLeft, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height), sf) boundLeft += CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), Me.Font).Width * 0.7) End If Next End Sub End Class Thanks Dave Dave wrote:
> Hey all, You don't say which VB you're using, but one clue that there's going to> > Ok, here's another of my fun questions. I want to rewrite the textbox > control in VB.NET. I need to implement superscript and subscript > within the box. Don't ask why, but I can't use RTF as my superscript > and subscript's are always numbers and are defined as specific > characters. ie. char(192) = superscript 1 > > Does anyone know how to inherit and change the onPaint method of the > textbox? I have created my own controlt o try and do this but > apparently the onPaint method is never called: be a problem is given in VB2005 when you type "overrides" in your new class, and OnPaint isn't in the list. After a little wandering through the docs, I found this: <http://msdn2.microsoft.com/en-us/library/7h62478z.aspx> " Note Overriding OnPaint will not allow you to modify the appearance of all controls. Those controls that have all of their painting done by Windows (for example, TextBox) never call their OnPaint method, and thus will never use the custom code. Refer to the Help documentation for the particular control you want to modify to see if the OnPaint method is available. For a list of all the Windows Form Controls, see Controls to Use on Windows Forms. If a control does not have OnPaint listed as a member method, you cannot alter its appearance by overriding this method. For more information about custom painting, see Custom Control Painting and Rendering. " I'm not sure what the best way to proceed would be; ideally you want to avoid having to do all the rendering yourself, but I think you may have to. It's not that hard, just a bit fiddly. -- Larry Lard Replies to group please > I'm not sure what the best way to proceed would be; ideally you want to Dont suppose you have any examples do you?> avoid having to do all the rendering yourself, but I think you may have > to. It's not that hard, just a bit fiddly. Add this:
Public Sub New() MyBase.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, True) MyBase.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, True) MyBase.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, True) End Sub /claes Show quoteHide quote "Dave" <davesa***@gmail.com> wrote in message news:1151395270.629843.321290@i40g2000cwc.googlegroups.com... > Hey all, > > Ok, here's another of my fun questions. I want to rewrite the textbox > control in VB.NET. I need to implement superscript and subscript > within the box. Don't ask why, but I can't use RTF as my superscript > and subscript's are always numbers and are defined as specific > characters. ie. char(192) = superscript 1 > > Does anyone know how to inherit and change the onPaint method of the > textbox? I have created my own controlt o try and do this but > apparently the onPaint method is never called: > > Public Class SuperTextBox > Inherits TextBox > > Protected Overrides Sub OnPaint(ByVal e As > System.Windows.Forms.PaintEventArgs) > Dim sf As New StringFormat > sf.LineAlignment = StringAlignment.Center > > e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), > e.ClipRectangle) > > Dim strToPrint As String = Me.Text > Dim boundLeft As Integer = e.ClipRectangle.Left > > For i As Integer = 0 To strToPrint.Length - 1 > If > clsSuperScriptHandler.isSubScript(CChar(strToPrint.Substring(i, 1))) > Then > 'subscript > Dim f As New Font(me.Font.FontFamily, _ > me.Font.Size - 3, _ > Me.Font.Style, _ > Me.Font.Unit) > > e.Graphics.DrawString(strToPrint.Substring(i, 1), f, _ > New SolidBrush(Me.ForeColor), New > RectangleF(boundLeft, e.ClipRectangle.Y + 5, e.ClipRectangle.Width, > e.ClipRectangle.Height), sf) > boundLeft += > CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), f).Width * > 0.7) > ElseIf > clsSuperScriptHandler.isSuperScript(CChar(strToPrint.Substring(i, 1))) > Then > 'superscript > Dim f As New Font(Me.Font.FontFamily, _ > Me.Font.Size - 3, _ > Me.Font.Style, _ > Me.Font.Unit) > > e.Graphics.DrawString(strToPrint.Substring(i, 1), f, _ > New SolidBrush(Me.ForeColor), New > RectangleF(boundLeft, e.ClipRectangle.Y - 5, e.ClipRectangle.Width, > e.ClipRectangle.Height), sf) > boundLeft += > CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), f).Width * > 0.7) > Else > 'normal script > e.Graphics.DrawString(strToPrint.Substring(i, 1), > Me.Font, _ > New SolidBrush(Me.ForeColor), New > RectangleF(boundLeft, e.ClipRectangle.Y, e.ClipRectangle.Width, > e.ClipRectangle.Height), sf) > boundLeft += > CInt(e.Graphics.MeasureString(strToPrint.Substring(i, 1), > Me.Font).Width * 0.7) > End If > Next > End Sub > End Class > > Thanks > > Dave >
Controling Event Sequencing...
dataset and where clause Dataset HasChanges function not true when Dataset is passed as variable button flash with red and white color Dates at Midnight [Regular Expression] match a word with interpunctuation DatagridView comboboxcolumn - assign cell value Getting saved values back to display after Update Serialize Treeview Control Find out the MAC-Adress of a server |
|||||||||||||||||||||||