Solved

Border colors on controls

Posted on 2004-10-12
8
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 28

Expert Comment

by:iboutchkine
ID: 12289125
sorry forgot to declare it

dim ctr as object
0
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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