Could someone comment the code in the OnPaint Method to explain what is going on? Thanks!
v-wywan wrote:
Hello Steve,Thanks for your mail.I also paste the reply in newsgroup.
21-Jun-07
Hello Steve
Thanks for your mail
I also paste the reply in newsgroup. Thus, more people could get benefit if
meet the same issue
I repro the issue and figure out this is a code defect
ColorGroupBox's onpaint event draw border and text in the wrong panel
Please replace OnPaint event as below. This change could get rid of the
issue
***********************************************************
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs
Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font
'Dim borderRect As Rectangle = e.ClipRectangl
Dim borderRect As Rectangle = Me.ClientRectangl
borderRect.Y = (borderRect.Y + (tSize.Height / 2)
borderRect.Height = (borderRect.Height - (tSize.Height / 2)
ControlPaint.DrawBorder(e.Graphics, borderRect, Me._borderColor,
ButtonBorderStyle.Solid
'Dim textRect As Rectangle = e.ClipRectangl
Dim textRect As Rectangle = Me.ClientRectangl
textRect.X = (textRect.X + 6
textRect.Width = tSize.Widt
textRect.Height = tSize.Heigh
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Blue),
textRect
End Su
***********************************************************
Hope this helps. Please let me know whether it works for you and I will
follow up
Have a great day
Sincerley
Wen Yua
Microsoft Online Community Support
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Previous Posts In This Thread:
Changing colour of Groupbox Border
Hi Al
Is there a way to change the colour of a Groupbox border in VB.net 200
I want to change it to whit
Can it be done in the onpaint event
Regard
Steve
Hello SteveAccording to your description, you need change the color of
Hello Stev
According to your description, you need change the color of Groupbox border
from Black to White. (In VB.net 2005 ). Please don't hesitate to correct me
if I misunderstand anything.
This is a common issue. Because there is no public borderColor propery for
Groupbox, we cannot modify it by default. However, capturing the onpaint
event is the right direction. You could create customer class which
inherited GroupBox and overid its OnPaint event to draw the border the way
you like
Zhi-Xin Ye provide a good sample for this issue. I also copy the content
as following for your convenience.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1256465&SiteID=
[Changing border color of GroupBox
Public Class myGroupBo
Inherits GroupBo
Private _borderColor As Colo
Public Sub New(
MyBase.New(
Me._borderColor = Color.Blac
End Su
Public Property BorderColor() As Colo
Ge
Return Me._borderColo
End Ge
Set(ByVal value As Color
Me._borderColor = valu
End Se
End Propert
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs
Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font
Dim borderRect As Rectangle = e.ClipRectangl
borderRect.Y = (borderRect.Y
+ (tSize.Height / 2)
borderRect.Height = (borderRect.Height
- (tSize.Height / 2)
ControlPaint.DrawBorder(e.Graphics, borderRect, Me._borderColor,
ButtonBorderStyle.Solid
Dim textRect As Rectangle = e.ClipRectangl
textRect.X = (textRect.X + 6
textRect.Width = tSize.Widt
textRect.Height = tSize.Heigh
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect
e.Graphics.DrawString(Me.Text, Me.Font, New
SolidBrush(Me.ForeColor), textRect
End Sub
End Class
1) Open the Solution Explorer, Add a new Class and name the class as
"myGroupBox"
2) Put the above code in this class, rebuild your project,
3) Then, you will see a "myGroupBox" control on your toolbox, it has a
"BorderColor" property on the Misc group in the property view.
Hope this helps. If you still have anything unclear, please feel free to
let me know. I'm glad to assist you.
Have a great day,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WenYuanThank you for the prompt replyExactly what I neededRegardsSteve"WenYuan
WenYuan
Thank you for the prompt reply
Exactly what I needed
Regards
Steve
Re: Changing colour of Groupbox Border
You are welcome. Steve.
Have a nice weekend.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WenYuanI am having problems with the supplied code for mygroupbox onpaintIf
WenYuan
I am having problems with the supplied code for mygroupbox onpaint
If mygroupbox is on a Tab control tab then when I click on another control
on the form, the groupbox ends up with numerous lines through it and the
only way to get rid of them is to do a refresh
It looks like it is redrawing in the wrong location and a different size
Refresh fixes it
How do you get a user control to behave like the originals, i.e refresh
properly?
The effect doesn't happen when the control is just on a form, only when on a
Tab control
Regards
Steve
Hello Steve,When does the issue occur?
Hello Steve,
When does the issue occur? (On designer mode in Visual Studio 2005 IDE or
the application built by VS 2005).
I have test the code on my VS 2005 sp1 machine.
I notice mygroupbox ends up with numerous lines when I drop some control
over it in design mode of VS 2005 IDE. However, after I build the project,
this issue doesn't happen in the exe file. It seems like the issue only
occurs in VS 2005 IDE in design mode.
Did I misunderstand anything here? Please kindly let me know whether this
is the issue you are looking for? Thus, I could do further analyze. Thanks.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi WenYuanIt happens to me in the IDE and in the application exe fileIt only
Hi WenYuan
It happens to me in the IDE and in the application exe file
It only happens when the Groupbox is on a Tab page, not when it is on a form
Regards
Steve
Dear SteveI'm sorry to say I still cannot reproduce the issue on my side.
Dear Steve
I'm sorry to say I still cannot reproduce the issue on my side.
The issue only occurs to me on Design mode in the IDE. In exe file, the
issue has gone away whether I put mygroupbox in Tab Page or not.
Is it possible for you to send me a simple project which I could reproduce
the issue on my side?
Thus, I could do further analyze and make sure we are talking about the
same problem.
My alias is (e-mail address removed). I'm waiting for your reply.
Have a great day.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Steve,Thanks for your mail.I also paste the reply in newsgroup.
Hello Steve,
Thanks for your mail.
I also paste the reply in newsgroup. Thus, more people could get benefit if
meet the same issue.
I repro the issue and figure out this is a code defect.
ColorGroupBox's onpaint event draw border and text in the wrong panel.
Please replace OnPaint event as below. This change could get rid of the
issue.
************************************************************
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)
'Dim borderRect As Rectangle = e.ClipRectangle
Dim borderRect As Rectangle = Me.ClientRectangle
borderRect.Y = (borderRect.Y + (tSize.Height / 2))
borderRect.Height = (borderRect.Height - (tSize.Height / 2))
ControlPaint.DrawBorder(e.Graphics, borderRect, Me._borderColor,
ButtonBorderStyle.Solid)
'Dim textRect As Rectangle = e.ClipRectangle
Dim textRect As Rectangle = Me.ClientRectangle
textRect.X = (textRect.X + 6)
textRect.Width = tSize.Width
textRect.Height = tSize.Height
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect)
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Blue),
textRect)
End Sub
************************************************************
Hope this helps. Please let me know whether it works for you and I will
follow up.
Have a great day,
Sincerley,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Steve,Thanks for your mail.I also paste the reply in newsgroup.
Can someone comment and explain what is going on here in the onPaint method?
Submitted via EggHeadCafe - Software Developer Portal of Choice
Silverlight 2 Beta 2 - Doing Data Part I
http://www.eggheadcafe.com/tutorial...cc-58558a7e83f8/silverlight-2-beta-2--do.aspx