Solved

Border colors on controls

Posted on 2004-10-12
8
374 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

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.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

631 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