|
-
Sep 9th, 2021, 10:20 AM
#1
Thread Starter
Member
Command buttons from upgrade and newly added in Visual Studio 2019 are different
There is a difference in appearance of the new command buttons that have been added in Visual Studio from the upgraded ones from VB6. What is the best way to make all of them look similar?
-
Sep 9th, 2021, 10:34 AM
#2
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
Make sure that they are the same type and then make sure that they all have their appearance-related properties set to the same values.
-
Sep 10th, 2021, 12:26 AM
#3
Thread Starter
Member
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
 Originally Posted by jmcilhinney
Make sure that they are the same type and then make sure that they all have their appearance-related properties set to the same values.
I had looked at the properties. FlatAppearance settings are the same, FlatStyle is Standard, Modifiers were different but I made them all Public. UseVisualStyleBackColor was different. This might be it.
However, I cannot put it in a for loop like For each ctrl in Form.Controls, ctrl.UseVisualStyleBackColor = True. Is there another way or will I have to manually change all of them on each form?
Last edited by VisualBeginner.NET; Sep 10th, 2021 at 12:47 AM.
-
Sep 10th, 2021, 12:48 AM
#4
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
If you're still having issues, post a screenshot of the UI and also post the contents of your designer code file. If you don't know how to find that, click the Show All Files button at the top of the Solution Explorer and then expand the node for your form.
-
Sep 10th, 2021, 12:51 AM
#5
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
 Originally Posted by VisualBeginner.NET
However, I cannot put it in a for loop like For each ctrl in Form.Controls, ctrl.UseVisualStyleBackColor = True. Is there another way or will I have to manually change all of them on each form?
If you do it in code then it would have to be done on a per-form basis, even if you do use a loop. If that property is set to False in the designer code file then you can do a Find & Replace In Files. You can do a Replace All if you do want them all replaced, otherwise you can Find Next and Replace as required.
If you want to do it in the designer itself, open a form and select all the Buttons, then set the property to False in the Properties window. Again, that's a per-form operation.
-
Sep 10th, 2021, 02:17 AM
#6
Thread Starter
Member
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
 Originally Posted by jmcilhinney
If you do it in code then it would have to be done on a per-form basis, even if you do use a loop. If that property is set to False in the designer code file then you can do a Find & Replace In Files. You can do a Replace All if you do want them all replaced, otherwise you can Find Next and Replace as required.
If you want to do it in the designer itself, open a form and select all the Buttons, then set the property to False in the Properties window. Again, that's a per-form operation.
Thanks. Now I understand (I think) what is going on. Even manually replacing is not difficult because I could select a lot of buttons using the pointer (and ctrl to add more) and then set the Visual style back color once for each form. I also see that I could have done it in the form designer but as a beginner, I am not supposed to mess with the designer files.
I still don't figure out how I could do it in code on each form because I still cannot write If TypeOf ctrl is button then ctrl.UseVisualStyleBackColor = True.
-
Sep 10th, 2021, 02:33 AM
#7
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
 Originally Posted by VisualBeginner.NET
I still don't figure out how I could do it in code on each form because I still cannot write If TypeOf ctrl is button then ctrl.UseVisualStyleBackColor = True.
UseVisualStyleBackColor is a member of ButtonBase, so you can only access it on a reference of that type or a derived type. If you wanted to do this on every Button then you would need a Button reference. You can get that in a number of ways:
vb.net Code:
For Each cntrl In Controls
If TypeOf cntrl Is Button Then
DirectCast(cntrl, Button).UseVisualStyleBackColor = True
End If
Next
vb.net Code:
For Each cntrl In Controls
Dim btn = TryCast(cntrl, Button)
If btn IsNot Nothing Then
btn.UseVisualStyleBackColor = True
End If
Next
vb.net Code:
For Each btn In Controls.OfType(Of Button)()
btn.UseVisualStyleBackColor = True
Next
-
Sep 10th, 2021, 02:50 AM
#8
Thread Starter
Member
Re: Command buttons from upgrade and newly added in Visual Studio 2019 are different
 Originally Posted by jmcilhinney
UseVisualStyleBackColor is a member of ButtonBase, so you can only access it on a reference of that type or a derived type. If you wanted to do this on every Button then you would need a Button reference. You can get that in a number of ways:
vb.net Code:
For Each cntrl In Controls
If TypeOf cntrl Is Button Then
DirectCast(cntrl, Button).UseVisualStyleBackColor = True
End If
Next
vb.net Code:
For Each cntrl In Controls
Dim btn = TryCast(cntrl, Button)
If btn IsNot Nothing Then
btn.UseVisualStyleBackColor = True
End If
Next
vb.net Code:
For Each btn In Controls.OfType(Of Button)()
btn.UseVisualStyleBackColor = True
Next
Thank you very much. I have to learn what these DirectCast and TryCast are. The third alternative is easier (but that too was new for me). For the time being, I just manually selected all the buttons and changed the Visual style back color.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|