Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Border colors on controls

Posted on 2004-10-12
8
Medium Priority
?
377 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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