-
Blue border appear around a Button? [Resolved]
Is there a straightforward way to make a Blue border appear around a command button?
I need the easiest method possible, I have a usercontrol with a single button on it and resizing is very straighforward. If I have to start juggling pictures and pixels and twips I will be very sad...
-
Re: Blue border appear around a Button?
What sort of border? The highlight you get with XP styles, or just 4 straight blue lines?
-
Re: Blue border appear around a Button?
The easiest way would probably be to use the Shape control. Do you need to border always there, or when you click the button?
-
Re: Blue border appear around a Button?
Hi I have made a sub for you.
All you need to do is add a shape control to your form called shape1, some where out of the way.
set the shape to rectangle, and the border color to blue.
Then pass the bellow sub the name of your commanbutton
VB Code:
Public Sub DoBlueBox(pCommandButton As CommandButton)
Shape1.Left = pCommandButton.Left - 10
Shape1.Top = pCommandButton.Top - 10
Shape1.Width = pCommandButton.Width + 20
Shape1.Height = pCommandButton.Height + 20
End Sub
-
Re: Blue border appear around a Button?
OK, reado, I will try your suggestion. Remember though, that this is a UserControl which has a single command button on it, and the resizing of the Usercontrol went something like this (OK, exactly like this):
VB Code:
Private Sub UserControl_Resize()
cmdButton.Height = Height
cmdButton.Width = Width
End Sub
Now, with the introduction of a second control, will screen resolution become a factor in the new UserControl_Resize routine? This complicates my resize routine.
Dave
-
Re: Blue border appear around a Button?
Also, there will be times when the button has no blue border (this is driven by external events in the system). So sometimes there will be no border. How will the UserControl look then?
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Datacide
The easiest way would probably be to use the Shape control. Do you need to border always there, or when you click the button?
The border will not always be there.
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by penagate
What sort of border? The highlight you get with XP styles, or just 4 straight blue lines?
Either way, I guess. This is a "Client Request" :rolleyes:
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by reado
Hi I have made a sub for you.
All you need to do is add a shape control to your form called shape1, some where out of the way.
set the shape to rectangle, and the border color to blue.
Then pass the bellow sub the name of your commanbutton
VB Code:
Public Sub DoBlueBox(pCommandButton As CommandButton)
Shape1.Left = pCommandButton.Left - 10
Shape1.Top = pCommandButton.Top - 10
Shape1.Width = pCommandButton.Width + 20
Shape1.Height = pCommandButton.Height + 20
End Sub
Very cool!
(PS: Datacide: Your quote is from the hacker's Manifesto by "the Mentor")
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Dave Sell
Either way, I guess. This is a "Client Request" :rolleyes:
Yay, one of those.
If you want another way...
Set your scalemode to Pixels. Add a picture box to your usercontrol with coordinates (0, 0) and name it picLines. Then move your cmdButton to (2, 2). Then try this resize code:
VB Code:
Private Sub UserControl_Resize()
cmdButton.Height = ScaleHeight - 4
cmdButton.Width = ScaleWidth - 4
With picLines
.Height = ScaleHeight
.Width = ScaleWidth
.Line (0, 0)-(.Width, 0), RGB(0, 0, 255)
.Line (.Width, 0)-(.Width, .Height), RGB(0, 0, 255)
.Line (.Width, .Height)-(0, .Height), RGB(0, 0, 255)
.Line (0, .Height)-(0, 0), RGB(0, 0, 255)
End With
End Sub
:)
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Hack
(PS: Datacide: Your quote is from the hacker's Manifesto by "the Mentor")
Did you get my PM about that Datacide :D
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by penagate
Did you get my PM about that Datacide :D
ya penagate, check my sig! :p
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by penagate
Yay, one of those.
If you want another way...
Set your scalemode to Pixels. Add a picture box to your usercontrol with coordinates (0, 0) and name it picLines. Then move your cmdButton to (2, 2). Then try this resize code:
VB Code:
Private Sub UserControl_Resize()
cmdButton.Height = ScaleHeight - 4
cmdButton.Width = ScaleWidth - 4
With picLines
.Height = ScaleHeight
.Width = ScaleWidth
.Line (0, 0)-(.Width, 0), RGB(0, 0, 255)
.Line (.Width, 0)-(.Width, .Height), RGB(0, 0, 255)
.Line (.Width, .Height)-(0, .Height), RGB(0, 0, 255)
.Line (0, .Height)-(0, 0), RGB(0, 0, 255)
End With
End Sub
:)
OK, thanks for going the extra mile, but I am still concerned what the UserControl will look like when I need the blue border to "go away"... Will there be a goofy background border? Maybe I can make the picbox transparent?
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by reado
Hi I have made a sub for you.
All you need to do is add a shape control to your form called shape1, some where out of the way.
set the shape to rectangle, and the border color to blue.
Then pass the bellow sub the name of your commanbutton
VB Code:
Public Sub DoBlueBox(pCommandButton As CommandButton)
Shape1.Left = pCommandButton.Left - 10
Shape1.Top = pCommandButton.Top - 10
Shape1.Width = pCommandButton.Width + 20
Shape1.Height = pCommandButton.Height + 20
End Sub
I changed you function a little, it will now accept a Shape and the Command button as well as the color of the border. Now this function can be used in a Module and will be available to the entire project.
VB Code:
Public Sub CmdButBorder(cntCmdBut As CommandButton, _
cntShape As Shape, _
Optional lngColor As Long = vbYellow)
Dim snlLeft As Single
Dim snlTop As Single
Dim snlWidth As Single
Dim snlHeight As Single
With cntCmdBut
snlLeft = .Left - 10
snlTop = .Top - 10
snlWidth = .Width + 25
snlHeight = .Height + 25
End With
With cntShape
.Move snlLeft, snlTop, snlWidth, snlHeight
.BorderColor = lngColor
End With
End Sub
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Dave Sell
OK, thanks for going the extra mile, but I am still concerned what the UserControl will look like when I need the blue border to "go away"... Will there be a goofy background border? Maybe I can make the picbox transparent?
No just use my function and change the border to the color of the background of the form etc.
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Mark Gambo
No just use my function and change the border to the color of the background of the form etc.
I will never know the color of the "form". This is a COM UserControl, which can be used all over the place. This is part of the problem.
-
Re: Blue border appear around a Button?
Try,
when you are done with the border, setting the mask colour of the usercontrol to RGB(0,0,255). Then it should nuke the lines.
-
Re: Blue border appear around a Button?
Quote:
Originally Posted by Dave Sell
I will never know the color of the "form". This is a COM UserControl, which can be used all over the place. This is part of the problem.
Sorry, I missed that, then why not setting the .Visible Property to false?
-
Re: Blue border appear around a Button?
Oh duh yes. Just set picLines.Visible = False. I tried the MaskColor and it didn't work anyway :(
-
1 Attachment(s)
Re: Blue border appear around a Button?
All,
Thanks for the great responses! I am uploading a simple sample control and then I will try your suggestions. You all are welcome to make your own mods to prove your points.
Just make a new "ActiveX Control" Project, and compile this control to an .OCX, then use it on a new EXE Form. You will see what I mean when you try these things.
-
1 Attachment(s)
Re: Blue border appear around a Button?
Here is my solution. Tell me what you think: Will I have problems on different screen resolutions (Curse the dreaded twip-monster).
VB Code:
Option Explicit
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 50
cmdButton.Left = 50
cmdButton.Height = Height - 100
cmdButton.Width = Width - 100
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 0
cmdButton.Left = 0
cmdButton.Height = Height
cmdButton.Width = Width
End Sub
Private Sub UserControl_Resize()
cmdButton.Height = Height
cmdButton.Width = Width
'
BlueBorder.Height = Height
BlueBorder.Width = Width
End Sub
-
Re: Blue border appear around a Button? [Resolved]
Twips are usually 15 to a pixel. But why don't you use ScaleMode as pixels instead? Then no more monster... ;)
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by penagate
Twips are usually 15 to a pixel.
Totally unpredictable. Twips are dependant on the client's Screen SIZE (ie.. 15" monitor diff than 19" monitor), and also screen resolution.
Quote:
Originally Posted by penagate
But why don't you use ScaleMode as pixels instead? Then no more monster... ;)
OK, I will try this for sure! :thumb:
-
Re: Blue border appear around a Button? [Resolved]
ScaleMode looks like it has to be twip. The UserControl goes out-of-control ugly in any other scale mode when dropped on a COM consumer (like a VB6 Form).
-
Re: Blue border appear around a Button? [Resolved]
Have you converted all your measurements to use the .ScaleHeight, .ScaleWidth properties, and to pixels rather than twips?
-
Re: Blue border appear around a Button? [Resolved]
VB Code:
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 5
cmdButton.Left = 5
cmdButton.Height = ScaleHeight - 10
cmdButton.Width = ScaleWidth - 10
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 0
cmdButton.Left = 0
cmdButton.Height = ScaleHeight
cmdButton.Width = ScaleWidth
End Sub
Private Sub UserControl_Resize()
cmdButton.Height = ScaleHeight
cmdButton.Width = ScaleWidth
'
BlueBorder.Height = ScaleHeight
BlueBorder.Width = ScaleWidth
End Sub
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by penagate
Have you converted all your measurements to use the .ScaleHeight, .ScaleWidth properties, and to pixels rather than twips?
How? They are just numbers. ScaleHeight = 102, and Scale Width = 189
What should they be?
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by Dave Sell
How? They are just numbers. ScaleHeight = 102, and Scale Width = 189
What should they be?
Did you try my code in post #26?
-
Re: Blue border appear around a Button? [Resolved]
I am not sure if this is what you what but take a look:
VB Code:
Option Explicit
Private Sub CmdButBorder(cntCmdBut As CommandButton, _
cntShape As Shape, _
Optional lngColor As Long = vbYellow)
Dim snlLeft As Single
Dim snlTop As Single
Dim snlWidth As Single
Dim snlHeight As Single
With cntShape
snlLeft = .Left + 10
snlTop = .Top + 10
snlWidth = .Width - 25
snlHeight = .Height - 25
.BorderColor = lngColor
End With
With cntCmdBut
.Move snlLeft, snlTop, snlWidth, snlHeight
End With
End Sub
Private Sub UserControl_Resize()
Shape1.Move 0, 0, Width, Height
cmdButton.Height = Shape1.Height + 25
cmdButton.Width = Shape1.Height + 10
Call CmdButBorder(cmdButton, Shape1, vbBlue)
End Sub
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.BorderColor = cmdButton.BackColor
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call CmdButBorder(cmdButton, Shape1, vbBlue)
End Sub
-
Re: Blue border appear around a Button? [Resolved]
A bit of an advertisement: UniCommand at CodeBank. It doesn't have a colored border all the time, just when the button is the default button. You can change the color by changing FillColor (or BorderColor, I can't remember if I changed it). Note that it doesn't support XP style (atleast afaik), but you can easily change the BorderStyle. And it also supports Unicode as the name states.
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by penagate
VB Code:
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 5
cmdButton.Left = 5
cmdButton.Height = ScaleHeight - 10
cmdButton.Width = ScaleWidth - 10
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.Top = 0
cmdButton.Left = 0
cmdButton.Height = ScaleHeight
cmdButton.Width = ScaleWidth
End Sub
Private Sub UserControl_Resize()
cmdButton.Height = ScaleHeight
cmdButton.Width = ScaleWidth
'
BlueBorder.Height = ScaleHeight
BlueBorder.Width = ScaleWidth
End Sub
I never tried this code, I just noticed your scaleW/H lines - I will try it now.
-
2 Attachment(s)
Re: Blue border appear around a Button? [Resolved]
Here is my final solution (minus my cool secret intellegence). Feel free to use or whatever. Notice the 2 DEsign-time Properties, Color and ColorBorderWidth.
Enjoy!
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by Dave Sell
Here is my final solution (minus my cool secret intellegence). Feel free to use or whatever. Notice the 2 DEsign-time Properties, Color and ColorBorderWidth.
Enjoy!
Nice control, good work! :bigyello:
-
Re: Blue border appear around a Button? [Resolved]
Quote:
Originally Posted by Mark Gambo
Nice control, good work! :bigyello:
Thanks, and thanks for all your input! I am adding another 2 Public Subs btw; .BorderOn and .BorderOff - you can guess what they do :D