Solved

Border colors on controls

Posted on 2004-10-12
8
367 Views
Last Modified: 2006-11-17
Is there a way to change the border color of a control such as a label, textbox, picturebox or the buttons inside a toolbar with code and could someone give a good working example?
0
Comment
Question by:teamdad
  • 5
  • 2
8 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 12288849
i asked this question a while ago.

there is a link in the question to this page

http://www.syncfusion.com/FAQ/WinForms/FAQ_c41c.asp#q609q

i did not try it, but it looks promsing

what i did go with was placing it inside a panel, it takes a little time to make sure the borders are the exact size you want them to be, but it definately saves on coding, and you still can move your controls around by dragging the panel

here is the link to my question

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21030890.html 

~b
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12288884
Private Sub form1_Paint(ByVal sender As Object, _
            ByVal e As PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = e.Graphics
        Dim pen As New Pen(Color.Red, 2.0)
        For Each ctr As Control In Me.Controls
            If TypeOf ctr Is TextBox Then
                g.DrawRectangle(pen, New _
                Rectangle(ctr.Location, ctr.Size))
            End If
        Next
        pen.Dispose()
    End Sub
0
 

Author Comment

by:teamdad
ID: 12289043
iboutchkine,

I like your code too but it puts a wavy blue line under ctr in the line For Each ctr As Control In Me.Controls and says "Name 'ctr' is not declared.
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12289125
sorry forgot to declare it

dim ctr as object
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 12289152
sorry screwed up again. Here is the final version

Private Sub form1_Paint(ByVal sender As Object, _
            ByVal e As PaintEventArgs) Handles MyBase.Paint

        Dim ctr As Control
        Dim g As Graphics = e.Graphics
        Dim pen As New Pen(Color.Red, 2.0)

        For Each ctr In Me.Controls
            If TypeOf ctr Is TextBox Then
                g.DrawRectangle(pen, New _
                Rectangle(ctr.Location, ctr.Size))
            End If
        Next
        pen.Dispose()
    End Sub
0
 

Author Comment

by:teamdad
ID: 12289227
Would there be a way to use this with my form when the mouse enters over a picturebox I want the label border to change colors and when the mouse leaves the picturebox the label border goes away.

0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12289342
Not that I know of
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12289552
Also you can put 2 labels on top of each other with different border color and then on mouse enter/leave event hide on eand show another
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

947 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now