TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dan Kling
NA
1
0
drawing a custom UserControl class of mine... not workin
Jul 6 2010 2:54 AM
Hey first-time poster here,
I've gotten into VB pretty smoothly so far, being able to figure out all of the bumps with me myself and Google... until this.
I'm making a custom class that mocks the System.Drawing.Rectangle class because the Rectangle class doesn't have a name property. I need a name property because I am adding all of my rectangles to a collection and I need a little more info stored than just their locale and size. So I changed the _onPaint event but nothing is working out when I run the program, here it is, please take a look and get back to me. Thanks! :) :) :) 8=D
Public Class Rectanglar : Inherits UserControl
Public BackgroundColor As Color = Color.Blue
Public Sub New(ByVal name As String, ByVal XY As Point, ByVal Widthy As Integer, ByVal Heighty As Integer)
Me.Location = XY
Me.Width = Widthy
Me.Height = Heighty
Me.UpdateBounds()
Dim graphics As Graphics = Me.CreateGraphics
Dim pen As Pen = New Pen(Color.Green)
graphics.DrawLine(pen, 0, 0, Me.Size.Width, Me.Size.Height)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim graphics As Graphics = e.Graphics
Dim penWidth As Integer = 4
Dim pen As Pen = New Pen(Color.Black, 4)
Dim fontHeight As Integer = 10
Dim font As Font = New Font("Arial", fontHeight)
Dim brush As SolidBrush = New SolidBrush(BackgroundColor)
graphics.FillEllipse(brush, 0, 0, Width, Height)
Dim textBrush As SolidBrush = New SolidBrush(Color.Black)
graphics.DrawEllipse(pen, CInt(penWidth / 2), CInt(penWidth / 2), Width - penWidth, Height - penWidth)
graphics.DrawString(Text, font, textBrush, penWidth, Height / 2 - fontHeight)
End Sub
End Class
'BUT instantiating that preceding code just didn't get the job done of drawing it for me.
'SO I supplemented the preceding code with the following to get it drawn.... which doens't work either. I've tried both separately.
Private Sub lblTEST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTEST.Click
Dim blah As Rectanglar = New Rectanglar("blah", New Point(50, 50), 500, 500)
blah.Update()
'the next stuff is the alternate way i tried to get SOMETHING drawn.
Dim graphics As Graphics = blah.CreateGraphics
Dim pen As Pen = New Pen(Color.Green)
graphics.DrawLine(pen, 0, 0, blah.Size.Width, blah.Size.Height)
So whatama doin wrong?
Reply
Answers (
0
)
image being used problem
Grab links from a Web page using VB.NET?