|
Do you have any plans on converting this class into a control?
Great work by the way...
|
|
|
|
|
|
Maybe this is helpful for someone using this nice control:
I still had heavy CPU issues (version 1.6). I realized that this is caused due to a "named" color selection. Using an "unnamed" ARGB-Value eliminated my CPU related problems.
|
|
|
|
|
Sorry could you show the part of code you think may need be touched. My computer is a Vista E6400 and the process is on 0 of CPU, tomorrow I'll try on XP to see if happens the same.
|
|
|
|
|
I haven't gone through the code yet. I just noticed that using something like button.ColorBase = Color.Red; will cause heavy CPU consumption in two different ways.
1. Hovering a button once => 80-99% CPU (this happens when ColorBase is set to a named color)
2. As long as the Cursor is hovering a button => 15-30% CPU => Leave Button => no more CPU usage (this happens when ColorOn is set to a named Color)
|
|
|
|
|
There are (only) two lines of code which have to be changed.
<br />
void timer1_Tick(object sender, EventArgs e)<br />
{<br />
(...)<br />
<br />
if (ColorOn == Color.FromArgb(R0, G0, B0))
{<br />
timer1.Stop();<br />
}<br />
<br />
(...)<br />
<br />
if (ColorBase == Color.FromArgb(A0, R0, G0, B0))
{<br />
timer1.Stop();<br />
}<br />
<br />
(...)<br />
}<br />
possible solution:
<br />
void timer1_Tick(object sender, EventArgs e)<br />
{<br />
(...)<br />
<br />
if (ColorOn.R == R0 && ColorOn.G == G0 && ColorOn.B == B0)<br />
{<br />
timer1.Stop();<br />
}<br />
<br />
(...)<br />
<br />
if (ColorBase.A == A0 && ColorBase.R == R0 && ColorBase.G == G0 && ColorBase.B == B0)<br />
{<br />
timer1.Stop();<br />
}<br />
<br />
(...)<br />
}<br />
Color.Red == "{Name=Red, ARGB=(255, 255, 0, 0)}" != "{Name=ffff0000, ARGB=(255, 255, 0, 0)}" == Color.FromArgb(255,255,0,0)
|
|
|
|
|
Typically you should compare colors by:
color1.ToArgb() == color2.ToArgb()
The default color comparison also takes the name into account, so this is better and faster.
Wout
|
|
|
|
|
Thank you very much for this code. Before my program would slow continuously as the program runtime increased. Now it can stay steady. Ty again.
|
|
|
|
|
Good Morning, first of all I have to say thanks a lot for your voting and opinion about the controls. Today I have updated the RibbonMenuButton with Solved Repaint ChangingSize, solved excesive CPU consuming. Added KeepPress and IsPress functionaliy.
I will publish RibbonRoundButton with RibbonFastMenu and RibbonForm during the day.
Thanks a lot
Note: Sorry if I dont reply every email, I read them and encourage myself to create better code.
|
|
|
|
|
Wow, I can't wait
You already got my 5, if only I could vote 6/5...
|
|
|
|
|
I don't know if i am the only one, but the example application always get my CPU to 10-20% even when it is reduced.
Any idea ?
Thanks !
|
|
|
|
|
me too.
In my PC when i use 6 RibbonMenuButton it took 50% CPU usage!!!
and my CPU is AMD X2 3800....
After replacing with standard button the cpu usage drop to 1%....
|
|
|
|
|
In Juan Pablo G.C. previous post, high CPU usage seems to be fixed but my post was about the sample application still using my CPU to 20% even when I do nothing at all.
Maybe this is the same problem, I hope
|
|
|
|
|
No more CPU usage problems with the v1.6 demo on my XP.
Thank you very much for this nice control
|
|
|
|
|
there is a suggestion why don't you place it on MicrosoftCodeplex.com or Sourceforge.net
its good idea to see such a good thing there.
|
|
|
|
|
Hi,
Thanks for a great article. I really enjoyed it.
Though i would let you know, if you put your regioning code
again in an overrided OnResize, it would fix the problem of
the button getting cut off.
Thanks anyway.
Later
|
|
|
|
|
Yes you are right, in another earlier post Sarnaa told me the same. I have updated but not uploaded, because I'm finishing the RibbonForm, RibbonFastMenu, RibbonContextMenu and the RibbonRoundButton. When I finished and I see all works I'll update this article and I'll publish the new one. Thanks for your comment.
|
|
|
|
|
can i use this for asp.net pages
if not
where can i find similar controls for asp.net
Any way your article rocks. Keep up the good work
Suman
|
|
|
|
|
I have left asp.net for a long time, if you tell me that exists something like OnPaint in asp.net I'll promise you to investigate it. Thanks
Juan Pablo G.C:
|
|
|
|
|
This is a great control and you've done some great work with it. One of the things thats missing is when the button is disabled you can't really tell that it's been disabled just by looking at the button. You have to actually try and click the button or move your mouse over and notice that it no longer highlights. What I've done is added a class to change the image from color to greyscale. The code to change the color was not from me but was from Bob Powell.
The following are the changes you need to make:
<br />
public void DrawImage(Graphics gr)<br />
{<br />
if (this.Image != null)<br />
{<br />
Image myImage = this.Image;<br />
<br />
if (this.Enabled == false) <br />
{<br />
RibbonStyle.RibbonGreyScaler grayScaler = new RibbonStyle.RibbonGreyScaler();<br />
myImage = grayScaler.ConvertToGreyScale(this.Image);<br />
}<br />
<br />
offsety = _imageoffset; offsetx = _imageoffset;<br />
if (_imagelocation == e_imagelocation.Left | _imagelocation == e_imagelocation.Right)<br />
{<br />
imageheight = this.Height - offsety * 2;<br />
if (imageheight > _maximagesize.Y & _maximagesize.Y != 0)<br />
{ imageheight = _maximagesize.Y; }<br />
imagewidth = (int)((Convert.ToDouble(imageheight) / myImage.Height) * myImage.Width);<br />
}<br />
else if (_imagelocation == e_imagelocation.Top | _imagelocation == e_imagelocation.Bottom)<br />
{<br />
imagewidth = this.Width - offsetx * 2;<br />
if (imagewidth > _maximagesize.X & _maximagesize.X != 0)<br />
{ imagewidth = _maximagesize.X; }<br />
imageheight = (int)((Convert.ToDouble(imagewidth) / myImage.Width) * myImage.Height);<br />
<br />
}<br />
switch (_imagelocation)<br />
{<br />
case e_imagelocation.Left:<br />
gr.DrawImage(myImage, new Rectangle(offsetx, offsety, imagewidth, imageheight));<br />
break;<br />
case e_imagelocation.Right:<br />
gr.DrawImage(myImage, new Rectangle(this.Width - imagewidth - offsetx, offsety, imagewidth, imageheight));<br />
break;<br />
case e_imagelocation.Top:<br />
offsetx = this.Width / 2 - imagewidth / 2;<br />
gr.DrawImage(myImage, new Rectangle(offsetx, offsety, imagewidth, imageheight));<br />
break;<br />
case e_imagelocation.Bottom:<br />
gr.DrawImage(myImage, new Rectangle(offsetx, this.Height - imageheight - offsety, imagewidth, imageheight));<br />
break;<br />
default:<br />
break;<br />
}<br />
}<br />
}<br />
You'll need to add this new class into the module:
<br />
public class RibbonGreyScaler<br />
{<br />
<br />
public Image ConvertToGreyScale(Image myImage)<br />
{<br />
Bitmap bm = new Bitmap(myImage.Width, myImage.Height);<br />
Graphics g = Graphics.FromImage(bm);<br />
<br />
<br />
<br />
ColorMatrix cm = new ColorMatrix(new float[][]{ new float[]{0.3f,0.3f,0.3f,0,0},<br />
new float[]{0.59f,0.59f,0.59f,0,0},<br />
new float[]{0.11f,0.11f,0.11f,0,0},<br />
new float[]{0,0,0,1,0,0},<br />
new float[]{0,0,0,0,1,0},<br />
new float[]{0,0,0,0,0,1}});<br />
<br />
ImageAttributes ia = new ImageAttributes();<br />
ia.SetColorMatrix(cm);<br />
g.DrawImage(myImage, new Rectangle(0, 0, myImage.Width, myImage.Height), 0, 0, myImage.Width, myImage.Height, GraphicsUnit.Pixel, ia);<br />
g.Dispose();<br />
return bm;<br />
}<br />
}<br />
What happens is before the image is painted, a check is made to see if the button is enabled. If it is then the original image is left alone. But if the button is disabled then the image is greyscaled.
|
|
|
|
|
<br />
protected override void OnResize(EventArgs e){<br />
Rectangle r = new Rectangle(new Point(-1, -1), new Size(this.Width + _radius, this.Height + _radius));<br />
if (this.Size != null){<br />
GraphicsPath pathregion = new GraphicsPath();<br />
DrawArc(r, pathregion);<br />
this.Region = new Region(pathregion);<br />
}<br />
base.OnResize(e);<br />
}<br />
small fix!
modified 3-Sep-19 21:02pm.
|
|
|
|
|
Thanks for this article Juan Pablo,
you save me a lot of deploy and probaly a lot of money.
Very good article, as the previous one.
It got my 5.
Dr.Luiji
Trust and you'll be trusted.
Cryptography API: The Next Generation (CNG) - How to crypt documents with C++ programming, here.
|
|
|
|
|
Juan Pablo:
Your choice of naming Enums the same as their properties will make using this control a challenge for any non-case-sensitive language (i.e. VB).
For example:
<br />
private arrow _arrow;<br />
public enum arrow<br />
{<br />
None, ToRight, ToDown<br />
}<br />
<br />
public arrow Arrow<br />
{<br />
get { return _arrow; }<br />
set { _arrow = value; this.Refresh(); }<br />
}<br />
Visual Basic cannot distinguish between "arrow" and "Arrow". I did some tweaking to rename the enum to ArrowType so the code looks as follows:
<br />
private ArrowType _arrow;<br />
public enum ArrowType<br />
{<br />
None, ToRight, ToDown<br />
}<br />
<br />
public ArrowType Arrow<br />
{<br />
get { return _arrow; }<br />
set { _arrow = value; this.Refresh(); }<br />
}<br />
I did this for a half-dozen other properties/enums to create a re-usable DLL that can be linked from VB or C#. Drop me a line if you want the code.
See Also: http://msdn2.microsoft.com/en-us/library/ms229043.aspx for naming conventions regarding capitalization.
|
|
|
|
|
Read my last reply in the following post: Very Cool but...
Juan Pablo G.C.
|
|
|
|
|
Very good piece bt i am wondering if i can use it in a vb.net application. Does it support it? or do i have to make some changes to it?
It is not who i am underneath but what i do that defines me!
|
|
|
|
|