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...
Last edited by Dave Sell; Jul 15th, 2005 at 10:02 AM.
Reason: Got a TON of help!
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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)
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
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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?
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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")
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:
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:
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?
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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.
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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).
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
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
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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]
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!
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
Re: Blue border appear around a Button? [Resolved]
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!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."