473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

New problem with User control...derived class..

OK, having answered my questions in a previous feed about pulling my derived
class into the IDE....

Here's a new problem that I'm hoping can be fixed and isn't a .NET bug....

I have created an inherited class based on the textbox... which, all I am
doing is allowing a forecolor to be set when .enabled is set to true.

it works nicely, EXCEPT that when I click into the box, the font (set as
default MS Sans 8.25pt) does not appear to be used and instead what looks
like an Arial 10pt or larger is used - and there is some messy painting
going on.....doesn't clear the original text and the 2 fonts run into each
other...

Here's the entire class;

Public Class LinkMAN_TextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)

End Sub

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

End Class

I suspect this may be a bug, but if anyone can help I'd appreciate it.

Thanks,
Graham
Nov 20 '05 #1
7 1453
Hi,

Try this. I solved some of the problems by only drawing the textbox
when it is readonly. I also invalidate when it recieves the wm_setcursor
message. Hope this helps.

Public Class ExtendedTextbox

Inherits TextBox

Public Sub New()

setstyle(ControlStyles.UserPaint, True)

End Sub

Protected Overrides Sub OnPaintBackground(ByVal pevent As
System.Windows.Forms.PaintEventArgs)

If Me.ReadOnly Then

pevent.Graphics.Clear(Me.BackColor)

Else

MyBase.OnPaintBackground(pevent)

End If

End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim br As New SolidBrush(Me.ForeColor)

Dim sf As New StringFormat

Dim rDraw As RectangleF = RectangleF.op_Implicit(Me.ClientRectangle)

rDraw.Inflate(-5, 0)

Select Case Me.TextAlign

Case HorizontalAlignment.Center

sf.Alignment = StringAlignment.Center

Case HorizontalAlignment.Left

sf.Alignment = StringAlignment.Near

Case HorizontalAlignment.Right

sf.Alignment = StringAlignment.Far

End Select

If Me.ReadOnly Then

e.Graphics.DrawString(Me.Text, Me.Font, br, rDraw, sf)

Else

MyBase.OnPaint(e)

End If

End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_SETCURSOR As Integer = &H20

If m.Msg = WM_SETCURSOR And Me.ReadOnly Then

Me.Invalidate()

Else

MyBase.WndProc(m)

End If

End Sub

End Class

Ken

--------------------------------

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:b7*********************@news20.bellglobal.com ...
OK, having answered my questions in a previous feed about pulling my
derived
class into the IDE....

Here's a new problem that I'm hoping can be fixed and isn't a .NET bug....

I have created an inherited class based on the textbox... which, all I am
doing is allowing a forecolor to be set when .enabled is set to true.

it works nicely, EXCEPT that when I click into the box, the font (set as
default MS Sans 8.25pt) does not appear to be used and instead what looks
like an Arial 10pt or larger is used - and there is some messy painting
going on.....doesn't clear the original text and the 2 fonts run into each
other...

Here's the entire class;

Public Class LinkMAN_TextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)

End Sub

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

End Class

I suspect this may be a bug, but if anyone can help I'd appreciate it.

Thanks,
Graham

Nov 20 '05 #2
Hi Ken,

Appears to raise more issues than resolving...

My disabled boxes show empty, and nothing changes on the enabled box - I'm
gonna try and play with performing the Mybase.?? methods and replace them
one at a time to see what happens - or indeed see if executing the mybase
methods still causes the problem - in which case it is safe to say these are
bugs???

Thanks,
Graham

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uy**************@TK2MSFTNGP12.phx.gbl...
Hi,

Try this. I solved some of the problems by only drawing the textbox when it is readonly. I also invalidate when it recieves the wm_setcursor
message. Hope this helps.

Public Class ExtendedTextbox

Inherits TextBox

Public Sub New()

setstyle(ControlStyles.UserPaint, True)

End Sub

Protected Overrides Sub OnPaintBackground(ByVal pevent As
System.Windows.Forms.PaintEventArgs)

If Me.ReadOnly Then

pevent.Graphics.Clear(Me.BackColor)

Else

MyBase.OnPaintBackground(pevent)

End If

End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim br As New SolidBrush(Me.ForeColor)

Dim sf As New StringFormat

Dim rDraw As RectangleF = RectangleF.op_Implicit(Me.ClientRectangle)

rDraw.Inflate(-5, 0)

Select Case Me.TextAlign

Case HorizontalAlignment.Center

sf.Alignment = StringAlignment.Center

Case HorizontalAlignment.Left

sf.Alignment = StringAlignment.Near

Case HorizontalAlignment.Right

sf.Alignment = StringAlignment.Far

End Select

If Me.ReadOnly Then

e.Graphics.DrawString(Me.Text, Me.Font, br, rDraw, sf)

Else

MyBase.OnPaint(e)

End If

End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_SETCURSOR As Integer = &H20

If m.Msg = WM_SETCURSOR And Me.ReadOnly Then

Me.Invalidate()

Else

MyBase.WndProc(m)

End If

End Sub

End Class

Ken

--------------------------------

"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:b7*********************@news20.bellglobal.com ...
OK, having answered my questions in a previous feed about pulling my
derived
class into the IDE....

Here's a new problem that I'm hoping can be fixed and isn't a .NET bug....
I have created an inherited class based on the textbox... which, all I am doing is allowing a forecolor to be set when .enabled is set to true.

it works nicely, EXCEPT that when I click into the box, the font (set as
default MS Sans 8.25pt) does not appear to be used and instead what looks like an Arial 10pt or larger is used - and there is some messy painting
going on.....doesn't clear the original text and the 2 fonts run into each other...

Here's the entire class;

Public Class LinkMAN_TextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)

End Sub

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

End Class

I suspect this may be a bug, but if anyone can help I'd appreciate it.

Thanks,
Graham


Nov 20 '05 #3
Hi Graham

This looks like the same problem that I am having with custom controls with
style set to userpaint.
I have been trying to solve the problem of TabItems not resizing to
accomodate the set Font in a userpaint TabControl, and it looks like this is
the problem. If I find the answer I'll post it. A quick look at MSDN shows
that when WM_GETFONT returns 0 the system default font is used to draw
text(which would probably be Arial 10) I cannot catch a WM_GETFONT or
WM_SETFONT message though, unless I remove the userpaint style.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:b7*********************@news20.bellglobal.com ...
OK, having answered my questions in a previous feed about pulling my derived class into the IDE....

Here's a new problem that I'm hoping can be fixed and isn't a .NET bug....

I have created an inherited class based on the textbox... which, all I am
doing is allowing a forecolor to be set when .enabled is set to true.

it works nicely, EXCEPT that when I click into the box, the font (set as
default MS Sans 8.25pt) does not appear to be used and instead what looks
like an Arial 10pt or larger is used - and there is some messy painting
going on.....doesn't clear the original text and the 2 fonts run into each
other...

Here's the entire class;

Public Class LinkMAN_TextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)

End Sub

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

End Class

I suspect this may be a bug, but if anyone can help I'd appreciate it.

Thanks,
Graham

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004
Nov 20 '05 #4
Thanks Mick - if you do manage to find a solution, feel free to let me know.

In the meantime, any ideas on my recourse - should this be reported as a bug
to MS - if it hasn't already - and is there a 'correct' way to reporting
these?
Thanks,
Graham

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eQ*************@TK2MSFTNGP10.phx.gbl...
Hi Graham

This looks like the same problem that I am having with custom controls with style set to userpaint.
I have been trying to solve the problem of TabItems not resizing to
accomodate the set Font in a userpaint TabControl, and it looks like this is the problem. If I find the answer I'll post it. A quick look at MSDN shows
that when WM_GETFONT returns 0 the system default font is used to draw
text(which would probably be Arial 10) I cannot catch a WM_GETFONT or
WM_SETFONT message though, unless I remove the userpaint style.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:b7*********************@news20.bellglobal.com ...
OK, having answered my questions in a previous feed about pulling my

derived
class into the IDE....

Here's a new problem that I'm hoping can be fixed and isn't a .NET bug....
I have created an inherited class based on the textbox... which, all I am doing is allowing a forecolor to be set when .enabled is set to true.

it works nicely, EXCEPT that when I click into the box, the font (set as
default MS Sans 8.25pt) does not appear to be used and instead what looks like an Arial 10pt or larger is used - and there is some messy painting
going on.....doesn't clear the original text and the 2 fonts run into each other...

Here's the entire class;

Public Class LinkMAN_TextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)

End Sub

Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

End Class

I suspect this may be a bug, but if anyone can help I'd appreciate it.

Thanks,
Graham

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004

Nov 20 '05 #5
I can't get it to play nicely. I can change the font, but it's not quite the
right size.

In sub New() add the line:
\\\
Font = New Font(Font, Font.Size)
///

Then add:
\\\
Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
MyBase.OnFontChanged(e)
Const WM_SETFONT As Integer = &H30
WndProc(Message.Create(Handle, WM_SETFONT, Font.ToHfont, IntPtr.Zero))
End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004
Nov 20 '05 #6
Hi Mick,

It certainly put me on the right track - and think I've cracked it. Well ...
at least for this particular scenario. I can change the forecolour of my
disabled boxes...

Notice I used Font.Style instead of Font.Size in the Font assign.

Anyway, this is what I have ended up with...

Public Class ExtendedTextBox

Inherits System.Windows.Forms.TextBox

Public Sub New()
MyBase.New()
Font = New Font(Font, Font.Style)
End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim drawBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, 0.0F, 0.0F)
End Sub

Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
MyBase.OnFontChanged(e)
Const WM_SETFONT As Integer = &H30
WndProc(Message.Create(Handle, WM_SETFONT, Font.ToHfont,
IntPtr.Zero))
End Sub

Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
MyBase.OnEnabledChanged(e)
If Not Me.Enabled Then
Me.SetStyle(ControlStyles.UserPaint, True)
End If
End Sub

End Class

Thanks for all your help guys!
Graham


"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:ee**************@TK2MSFTNGP09.phx.gbl...
I can't get it to play nicely. I can change the font, but it's not quite the right size.

In sub New() add the line:
\\\
Font = New Font(Font, Font.Size)
///

Then add:
\\\
Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
MyBase.OnFontChanged(e)
Const WM_SETFONT As Integer = &H30
WndProc(Message.Create(Handle, WM_SETFONT, Font.ToHfont, IntPtr.Zero))
End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004

Nov 20 '05 #7
Yes, I started with Font.Style and made several changes whilst trying to get
the correct size. There's not much of a difference, but there is one.

What I have found, is that EnableVisualStyles messes up the TabSize in my
TabControl, but it didn't appear to make any difference to the TextBox. I
have disabled Visual Styles in my TabControl and Tabs now seem to size
correctly if they have a relatively short Text (Items with a long Text give
me some curious results).

I would probably never have thought to look at WM_SETTEXT if I hadn't seen
your post, so Thankyou for finding this problem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Graham Blandford" <gr**************@sympatico.ca> wrote in message
news:Sw********************@news20.bellglobal.com. ..
Hi Mick,

It certainly put me on the right track - and think I've cracked it. Well .... at least for this particular scenario. I can change the forecolour of my
disabled boxes...

Notice I used Font.Style instead of Font.Size in the Font assign.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Verane | last post by:
Hi all, I want to define a user control (called BaseUserControl) in one assembly, and define another user control (called derivedUserControl) in another assembly which derived from...
4
by: DotNetJunkies User | last post by:
I have created a User Control (a Pareto Chart) using C#. It works great in .Net Windows Apps, but I also need to use it in a Web Application (to view in IE). Everything I read on this seems to be...
1
by: Charlie | last post by:
Hi: When I derive a new user control from an existing user control that contains UI elements (buttons, textboxes, etc.) and put derived control on a form, UI elements don't appear when I run the...
1
by: ABC | last post by:
I write a Base Web User Control which contains several public properties and a Inherited Web User Control which only have some codes in new method. When I use the Inherited Web User Control on Web...
7
by: BradC | last post by:
(VB.NET 2002, Windows app). I'm going to be provided a two-letter string like "BV" or "TP" that represents a location. I then need to perform some actions on several form controls that have...
0
by: mschep | last post by:
Hi, I built an assembly with a set of user controls. This can be done with the Visual Studio 2005 Deployment Project: building and merging for example all your aspx and ascx in one dll (lets...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
3
by: Jonathan Wood | last post by:
I could really use some help on this. First of all, I want to create a Web control where I render the control completely from scratch based on information from a database. In the book...
6
by: ajk | last post by:
Hi I was wondering how to show different properties in design and run-mode for a user control? Is it possible to do this when implementing the System.ComponentModel.ICustomTypeDescriptor...
1
by: =?Utf-8?B?Q2hyaXN0aWFuIFdlaW5lcnQ=?= | last post by:
Hello, I currently fight with a problem during the derivative of WinForm controls. In Visual Studio I created a new User Control. This control is derived from the DataGridView of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.