Solved

Border colors on controls

Posted on 2004-10-12
8
366 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

19 Experts available now in Live!

Get 1:1 Help Now