FontColor Icon change based on selection
My question is pretty simple: How can I change the icon based on the color selection?
Say I start with an A underlined with red. If I select Blue from the colorpicker, how do I get that blue under my A?
开发者_高级运维Thanks Team JoKi
Your question is surprisingly lacking in necessary details, so I'm going to try and see if I can fill in some of the blanks...
I assume that by "the icon", you mean one that you've found that looks similar to the one used in Microsoft Word:
And I assume that you've placed that icon in some type of toolbar. And I further assume that, upon clicking the icon (or the drop-down arrow next to the icon) in the toolbar, the user is presented with a color-picker control, from which they can select a custom color.So your question is, how can I change that default red underline to match the color that the user has selected in my color picker control.
The short answer is that you can't. If you pay close attention, most applications don't update the color of this icon in accordance with the chosen color. It's way more work than it's worth, considering that it will add little value to your application once complete. Surprisingly few users will even notice this "feature".
But if you want to do this, you'll need to create and modify an icon on-the-fly, after the user has chosen a color. Start with a template icon, one without any color filled in for the color rectangle at all. You can create this from your existing icon using an icon editor application (like my personal favorite, IcoFX).
Once you've created your template icon, you need to write code that loads this icon into a bitmap (System.Drawing.Bitmap
), fills the appropriate rectangular region with the selected color (Graphics.FillRectangle
), and then converts that bitmap back into an icon. Finally, assign the icon you've created in memory to the toolbar button, and marvel what what you've accomplished.
精彩评论