Replacing Font or Color

Friday, 20 November 2009 14:23 by John Shawyer

When designing a Form it is often useful to change the colors of some controls or the font of text controls on the Form.

Below is the Form "Phrase Header” from the Phrase XML project (you may wish to download this project).

 PhraseXMLSetup.msi (397.00 kb)

In the sample below the color of the central panel has been set to “Blue”, and the font to “Pristina Size 14”.

 

Now it would be really useful if the end user was able to do this type of adjustment themselves!

This is one way to give the end user the ability to change both the color and font for any of the Forms controls.

1. A ContextMenuStrip is added to the property ContextMenuStrip of the Forms property sheet. It will detail the font and color changes you wish the user to decide upon. If the user presses the right hand mouse button the user will see your ContextMenuStrip:

 

2. If the user selects “Panel Color” the user will see:

 

3. Selecting the “Blue” color the user will see:

 

4. In Section 1 you can select “Change All Fonts”, you can similarly adjust the font to “Pristina Size 14”.

 

So lets examine what happens to the Visual Basic code.

All these functions and methods operate in the same way. If we examine how the user changes the color to "Blue".

When the user selects "Blue" from the Color menu in Section 2, this value is passed to a sub called color to PanelToolStriipMenuItem_Click.

The panel is named panel2.

    Private Sub PanelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ForeColourToolStripMenuItem.Click        

        PanelBack(1) = Me.Panel2

        ReplaceColor.Show()

    End Sub

We have a form called "ReplaceColor.vb" and a Class called "FontColor.vb"

Form "ReplaceColor.vb"

 Imports System.Windows.Forms

Public Class ReplaceColor

    Private Sub ReplaceColor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim MyDialog As New ColorDialog()

        MyDialog.AllowFullOpen = True

        MyDialog.AnyColor = True

        MyDialog.SolidColorOnly = False

        MyDialog.ShowHelp = True

        If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then

            Me.BackColor = MyDialog.Color

            ColorSelect = MyDialog.Color

            num = Nothing

            Do Until num > 20

                If TypeOf PanelBack(num) Is System.Windows.Forms.Panel Then

                    ChangeControlBack(PanelBack(num), ColorSelect)

                    PanelBack(num) = Nothing

                End If

                num = num + 1

            Loop

            Me.Close()

        End If

    End Sub

End Class

Class "ColorFont.vb"

Imports System.Windows.Forms.ColorDialog

Module ColourFont

    Public num As Integer

    Public PanelBack(20) As Panel

    Public FontSelect As Font

    Public ColorSelect As Color

    Public Function ChangeControlBack(ByVal MyPath As Control, ByVal myColor As Color) As Integer

        MyPath.BackColor = myColor

        ChangeControlBack = 1

    End Function

End Module

 Saving these settings

These application setting allow us to store and retrieve these property settings.

To find these settings look under My Project and then Settings:

These are set in the control properties:

 

Comments

January 9. 2010 16:14

women bodybuilding

You got a really useful blog I have been here reading for about an hour. I am a newbie and your success is very much an inspiration for me.

women bodybuilding

January 13. 2010 11:32

offshore savings accounts

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

offshore savings accounts

January 14. 2010 20:04

how to stay married

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

how to stay married

January 15. 2010 22:47

Astral Travel

Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I'm more of a visual learner,I found that to be more helpful well let me know how it turns out! I love what you guys are always up too. Such clever work and reporting! Keep up the great works guys I've added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.

Astral Travel

January 16. 2010 04:10

outdoor storage cabinet

Great post! I am just starting out in community management/marketing media and trying to learn how to do it well - resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case.

outdoor storage cabinet

January 19. 2010 16:08

Gas Fire Pit

I personally have embraced the new technologies and the CMS platforms, I think the new tools only make the web designs better. I am glad that new technologies are coming out in web design that make things easier, improved, and better looking for design.

Gas Fire Pit

January 29. 2010 15:31

bed linens

Just wanted to give you a shout from the valley of the sun, great information. Much appreciated.

bed linens

January 31. 2010 05:48

IT contractor accountants

Couldn?t be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!

IT contractor accountants

February 1. 2010 15:57

infrared saunas

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article.

infrared saunas

February 5. 2010 04:44

acne scar remedies

I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful.

acne scar remedies

February 6. 2010 07:31

boise home listings

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

boise home listings

February 11. 2010 02:47

how to build a greenhouse

Resources like the one you mentioned here will be very useful to me! I will post a link to this page on my blog. I am sure my visitors will find that very useful.

how to build a greenhouse

February 14. 2010 02:01

game downloads

Me and my friend were arguing about an issue similar to this! Now I know that I was right. lol! Thanks for the information you post.

game downloads

February 16. 2010 10:30

best acne treatment

I have been surfing online more than three hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.

best acne treatment

February 16. 2010 10:31

best acne treatment

How-do-you-do, just needed you to know I have added your site to my Google bookmarks because of your extraordinary blog layout. But seriously, I think your site has one of the freshest theme I've came across. It really helps make reading your blog a lot easier.

best acne treatment

February 19. 2010 03:08

Hanover home buiders

How-do-you-do, just needed you to know I have added your site to my Google bookmarks because of your extraordinary blog layout. But seriously, I think your site has one of the freshest theme I've came across. It really helps make reading your blog a lot easier.

Hanover home buiders

February 19. 2010 07:41

Bee Enochs

Hello, nice day.. Your article is very striking. I never imagined that it was feasible to accomplish something like that until after I checked out your content. You definitely offered an incredible understanding on exactly how this whole system works. I will make sure to return for more information. Keep it up!

Bee Enochs

February 28. 2010 21:22

umbrella payroll

Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it's driving me mad so any assistance is very much appreciated.

umbrella payroll

March 7. 2010 06:05

Alecia Hendry

Hi webmaster - This is by far the best looking site I’ve seen. It was completely easy to navigate and it was easy to look for the information I needed. Fantastic layout and great content! Every site should have that. Awesome job

Alecia Hendry

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading