?
Solved

VB.NET - paint a custom border around a control

Posted on 2008-01-30
3
Medium Priority
?
2,870 Views
Last Modified: 2008-02-11
I want to paint a custom border around a control. The border needs to resize appropriately.
0
Comment
Question by:tricks801
  • 2
3 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20778106
Something like this?
 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = e.Graphics
        g.DrawRectangle(Pens.Blue, New Rectangle(CheckBox1.Left - 3, CheckBox1.Top - 3, CheckBox1.Width + 6, CheckBox1.Height + 6))
    End Sub

Open in new window

0
 

Author Comment

by:tricks801
ID: 20779254
will that work even when the form is resized. The control in my case is a grid and its anchored to all sides.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 20779625
It will work if you invalidate the form in the resize event so that it's repainted properly.  (Full sample, just add a checkbox to a form and the following code)
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CheckBox1.AutoSize = False
        CheckBox1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = e.Graphics
        g.DrawRectangle(Pens.Blue, New Rectangle(CheckBox1.Left - 3, CheckBox1.Top - 3, CheckBox1.Width + 6, CheckBox1.Height + 6))
    End Sub
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Invalidate()
    End Sub
End Class

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question