|
CPU 100%
Comment corriger.
|
|
|
|
|
Hi pablo,
I've been using your work and it is very useful for me. I've been trying to improve the form and found a way.
I overrided the WndProc method of the form and used your drawing algorithm and it work great! Please give it a try.
Greetings.
|
|
|
|
|
I suggest other people to not use the roundbutton control until its fixed because of performance problems. The CPU is running up to 100% while hovering the control with the mouse.
The timer never stops:
if (ColorOn == Color.FromArgb(R0, G0, B0))
{
timer1.Stop();
}
Together with
timer1.Interval = 1;
The cpu speed will run up to 100%.
|
|
|
|
|
As a simple fix to the above I changed in RibbonRoundButton.cs:
if (ColorBase == Color.FromArgb(R0, G0, B0))
{
timer1.Stop();
}
else
{
this.Refresh();
}
to be:
if (ColorBase.ToArgb() == (int)(0xff000000 | (uint)R0<<16 | (uint)G0<<8 | (uint)B0) )
{
timer1.Stop();
}
else
{
this.Refresh();
}
This eliminates the CPU usage after the mouse leaves the button.
|
|
|
|
|
for code like....
int _r0 = R0 + 127, _g0 = G0 + 196, _b0 = B0 + 111;
if (_r0 > 255)
_r0 = 255;
if (_g0 > 255)
_g0 = 255;
if (_b0 > 255)
_b0 = 255;
use Math.Min instead, it looks neater; neater = more readable = better component.
int _r0 = Math.Min(255, R0 + 127);
int _g0 = Math.Min(255, G0 + 196);
int _b0 = Math.Min(255, B0 + 111);
|
|
|
|
|
The ribbon form example with the custom colours is terrible, on my Windows Server 2008 Datacenter Edition install the window flickers massively when recolouring. The window doesn't resize correctly, lagging and flickering horribly, not to mention the child controls behave very poorly. For resizing take a look at http://www.codeproject.com/KB/WPF/WPF_Window_Resizing.aspx[^], an article I recently did (and are due to update shortly to sort the pointer issue).
The fast menu is good, although the menu option popups perhaps need slightly better resizing (is it me or is the dialog oddly big also).
The glass / round buttons are great! Save a copy of that for some of my later work.
Combined example looks good on first view, but when opening the fast menu shows the fast menu on the taskbar. CPU load is 10-28% on a quad core cpu.
Do you like fishes? I do.
|
|
|
|
|
I think it could be interesting to keep the FormBorder property of the original form object (in fact the capability to disable resizing the form)
Are you agree?
|
|
|
|
|
public uint AC { get { return ac; } set { System.Math.Min(value, 255); } }
I think this is supposed to be
public uint AC { get { return ac; } set { ac = System.Math.Min(value, 255); } }
Also click-and-drag window moving is a bit wonky (it only works while the mouse is over the titlebar, and since your form is a bit slow at moving and redrawing you have to move the mouse real slooooow or else the window stops moving.
[Edit: I fixed this second problem. Wasn't too hard since it's only a page or two of code. I had converted it to VB.NET for my own project so the replacement code I cobbled together is also VB.NET, but it shouldn't be too hard to modify the original C# using it as a template.
What this code does is it only checks where the mouse cursor is on mouse down, instead of every mouse move, to determine whether it should size or move the window. The result is behavior closer to Windows' default.
#Region "Mouse Events"
Private Function SelectFormBorderAction() As formborderactions
Dim p As Point = PointToClient(Control.MousePosition)
If p.Y > Me.Height - cornerssize Then
'Bottom Right
If p.X > Me.Width - cornerssize Then
Return formborderactions.size_se
ElseIf p.X < cornerssize Then
'Bottom Left
Return formborderactions.size_sw
Else
'Bottom
Return formborderactions.size_s
End If
End If
If p.Y < cornerssize Then
'Top Right
If p.X > Me.Width - cornerssize Then
Return formborderactions.size_ne
ElseIf p.X < cornerssize Then
'Top Left
Return formborderactions.size_nw
ElseIf p.Y < 3 And p.X > cornerssize And p.X < Me.Width - cornerssize Then
'Top
Return formborderactions.size_n
Else
Return formborderactions.moving
End If
ElseIf p.X < cornerssize Then
Return formborderactions.size_w
ElseIf p.X > Me.Width - cornerssize Then
Return formborderactions.size_e
End If
Return formborderactions.none
End Function
Private _mousedown As Boolean = False
Private p_mouseoffset As Point
Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
_mousedown = True
p_mouseoffset = PointToClient(Control.MousePosition)
formborderaction = SelectFormBorderAction()
Me.Refresh()
MyBase.OnMouseDown(e)
End Sub
Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
_mousedown = False
formborderaction = formborderactions.none
Me.Refresh()
MyBase.OnMouseUp(e)
End Sub
Private Enum formborderactions As Integer
none
moving
size_nw
size_n
size_ne
size_w
size_e
size_sw
size_s
size_se
End Enum
Private formborderaction As formborderactions = formborderactions.none
Private cornerssize As Integer = 30
Private _mouseposonwindow As Point
Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
_mouseposonwindow = PointToClient(Control.MousePosition)
If Not _mousedown Then
Select Case SelectFormBorderAction()
Case formborderactions.moving, formborderactions.none
Cursor = Cursors.Arrow
Case formborderactions.size_e, formborderactions.size_w
Cursor = Cursors.SizeWE
Case formborderactions.size_n, formborderactions.size_s
Cursor = Cursors.SizeNS
Case formborderactions.size_ne, formborderactions.size_sw
Cursor = Cursors.SizeNESW
Case formborderactions.size_nw, formborderactions.size_se
Cursor = Cursors.SizeNWSE
End Select
Else
Select Case formborderaction
Case formborderactions.moving
Dim mouseposonscreen As Point = Control.MousePosition
mouseposonscreen.X = mouseposonscreen.X - p_mouseoffset.X
mouseposonscreen.Y = mouseposonscreen.Y - p_mouseoffset.Y
Me.Location = mouseposonscreen
Case formborderactions.size_e
Me.Size = New Size(_mouseposonwindow.X, Me.Height)
Case formborderactions.size_n
Me.Location = New Point(Me.Location.X, Me.Location.Y + e.Y)
Me.Size = New Size(Me.Width, Me.Height - e.Y)
Case formborderactions.size_ne
Me.Location = New Point(Me.Location.X, Me.Location.Y + e.Y)
Me.Size = New Size(_mouseposonwindow.X, Me.Height - e.Y)
Case formborderactions.size_nw
Me.Location = New Point(Me.Location.X + e.X, Me.Location.Y + e.Y)
Me.Size = New Size(Me.Width - e.X, Me.Height - e.Y)
Case formborderactions.size_s
Me.Size = New Size(Me.Width, _mouseposonwindow.Y)
Case formborderactions.size_se
Me.Size = New Size(_mouseposonwindow.X, _mouseposonwindow.Y)
Case formborderactions.size_sw
Me.Location = New Point(Me.Location.X + _mouseposonwindow.X, Me.Location.Y)
Me.Size = New Size(Me.Width - e.X, _mouseposonwindow.Y)
Case formborderactions.size_w
Me.Location = New Point(Me.Location.X + e.X, Me.Location.Y)
Me.Size = New Size(Me.Width - e.X, Me.Height)
End Select
End If
End Sub
#End Region
[Edit: RibbonMenuButton.cs is not included in the RibbonFastMenu class zip. That code won't compile without it. Fortunately it's included in the sample. In addition RibbonFastMenu.cs seems to contain code from the Sample, meaning more files from the sample are needed to get it to build, including resources.]
-- modified at 17:32 Friday 17th August, 2007
|
|
|
|
|
Could you share VB.NET converted code of RibbonForm?
Young programmer
|
|
|
|
|
why when using these controls the cpu usage is rising to 100%???
besides that, this is wayy cool!
Roey
Don't believe to what you hear on the news...
|
|
|
|
|
I was thinking list boxes and in particule the scroll bars in list boxes - I cant find a way to repaint them.
any ideas?
how about an article on how to apple ribbon on "non button" based controls such as listboxes , datagrids etc.
thanks
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
Howto put text on the ribbon round button? I have set the some text by the Properites->Text, but it is not shown up.
Best regards!
Le
|
|
|
|
|
I must say, YOU HAVE A TALENT! I've been looking for this kind of thing for a long time... Would you mind if I used some of this in a commercial product I am working on??? I will give you credit for what you've done...
Sniper167
|
|
|
|
|
Thanks Sniper, you can use the code as you wish, you can always donate in my blog if you wish on the middle right
Overrider Blog
|
|
|
|
|
On my computer, this thing is rubbish right now.
It looks nice enough in the pictures, and when I launch the Sample_RibbonTest app and the form first appears on screen, it still does, but once I try to interact with the control, it immediately looses all of it's appeal.
When I try to drag the window around, it gets some ugly light tone and all buttons etc. vanish (might be intentional), the form flickers terribly and the drag process is totally unreliable - i.e. every second or so, the dragging will simply come to a halt, as if I had released the mouse button. One in three times this happens, the control will also assume I had attempted to resize it and enlarge or shrink itself.
Clicking on the application button on the top left will again cause major flickering, and then a menu will appear (sortof) - out of place and in the foreground, with a part of a pink circle, presumably a placeholder intended to be hidden behind the app button itself.
While this is fine for a 0.01, I wouldn't consider it worth uploading to (or downloading from) CP in this condition.
Was really disappointed about this control after seeing the excellent (if not actually looking "right") ribbonTab control which works like a charm - I wonder what the deal is with the immense difference in quality between the two releases.
_______
MarcoK
|
|
|
|
|
Congratulations!!!
Your work is excellent but have a problem in resize the RibbonForm in two monitors...
Acertar en el camino...
|
|
|
|
|
OK! Thanks a lot. Your example is very good. I think I can make my application with your help.
Thank you
My blog: http://hoana2007.spaces.live.com
what i want is waht i've got
|
|
|
|
|
Hi,
first of all, nice work. I see that you must have put a lot of effort into making this. I think lot of people really appreciate it.
There's one big BUT.
It should be a good manner of each developer to free any umanaged resources as soon as they are no longer needed and not to rely on garbage collector to do his job (if you did the same with GDI you would end up in real trouble).
So I would recommend doing heavy refactoring of your code to handle this (it can speed up things a litle bit).
Instead of writing
GraphicsPath path = new GraphicsPath();<br />
...<br />
rather do
using (GraphicsPath path = new GraphicsPath())<br />
{<br />
...<br />
}<br />
My other advice concerns optimization: PRECOMPUTE everything you can.
e.g. In your fading stuff you compute all differences everytime the control fades in/out instead you can precompute an array of fade colors and then just use an index to this array. All your paths can be computed in advance as well (you can/should then implement Dispose() and in that method dispose of all your "permanent" graphics objects)
Next you can ease some pain by separating drawing into OnPaint and OnPaintBackground.
But keep it real man, good job...
Razz
|
|
|
|
|
Thanks for you great job!
Just one thing, sometimes the RibbonForm size will be error when dragging it. Also the performance should be improved. Hope it'll be better.
|
|
|
|
|
Juan,
I think you have shown you have a real talent for UI components/controls.
I must point out 1 thing. You are creating components/controls for .NET 2.0, which is a saturated market. If my company wants nice controls on a project, we would buy a suite of controls, for not much money when you consider how much the project is worth. I appreciate yours are free and useful to learn how to do some nice stuff, which is good.
I am not knocking your efforts, I think you rock. What I would say, is that you should download expression Blend BETA, and .NET 3.0, and come up with some WPF controls. This is a new market with not really anyone doing much as yet, mainly cos most folk dont get it and it scares the pants of them. Its very different.
So I think you could make a stack of credit/cash/fame/honour, what ever it is you seek, by ditching this .NET 2.0 stuff in favour of .NET 3.0 stuff.
Heres one I created earlier, and I dont have your artistic flair I know that for sure
http://www.codeproject.com/useritems/WPFFlickr.asp
So if I can do this, you would do much better.
Remember .NET 2.0 controls are everywhere, try and find a similiar control for .NET 3.0 and youll find nothing. OK this is because in WPF you can do almost what you want, Believe me I know. I've been messing with it a lot. I actually have a new article onn WPF/and electronic ink very soon.
I just think you have talent and it would be nice to see you use it to make something new, that will be ahead of its time instead of mimicing what is already available.
Of course if you go ahead with this idea, of mine, and become a multi-billionaire/millionaire I want 50%, or that beer in brighton you promised for beating me in last months C# comp. No, I am happy you won, well deserved.
Anyways, what do you think of this. New stuff is cool, so push it to the new stuff, you never know what you'll create (ooh aah, very frankenstein like, bring it on).
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
Sacha
Of course you are right (I think U.K. must give you the name of Lord . Take look at my blog, my point is to finish this control library and between put the new way of overriding controls and new code with Orcas and Blend.
Thanks Sacha, and don't worry I wondering with your articles I always review them
|
|
|
|
|
Yeah I appreciate the work you are doing.
I would never use it myself, as although I like UIs, I dont like overriding this that and the other to do it.
WPF on the other hand is simply awesome, I cant think of enough good things to say about it.
For example take one of your gradient buttons, here is the equivalent WPF/XAML code. Took 2 minutes to do with BLEND.
<Style x:Key="ButtonFocusVisual"><br />
<Setter Property="Control.Template"><br />
<Setter.Value><br />
<ControlTemplate><br />
<Rectangle SnapsToDevicePixels="true" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="3"/><br />
</ControlTemplate><br />
</Setter.Value><br />
</Setter><br />
</Style><br />
<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0"><br />
<GradientStop Color="#FFFFFFFF" Offset="0"/><br />
<GradientStop Color="#FFF0F0EA" Offset="0.9"/><br />
</LinearGradientBrush><br />
<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/><br />
<Style x:Key="GradientButton" TargetType="{x:Type Button}"><br />
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/><br />
<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/><br />
<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/><br />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/><br />
<Setter Property="HorizontalContentAlignment" Value="Center"/><br />
<Setter Property="VerticalContentAlignment" Value="Center"/><br />
<Setter Property="Template"><br />
<Setter.Value><br />
<ControlTemplate TargetType="{x:Type Button}"><br />
<Border Width="Auto" Height="Auto" BorderBrush="#FF3F3F9A" BorderThickness="2,2,2,2" CornerRadius="5,5,5,5"><br />
<Border.Background><br />
<LinearGradientBrush EndPoint="0.92,0.266" StartPoint="0.92,1.409"><br />
<GradientStop Color="#FF14252E" Offset="0"/><br />
<GradientStop Color="#FFB0E3FE" Offset="1"/><br />
</LinearGradientBrush><br />
</Border.Background><br />
<ContentPresenter HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center" Width="Auto" Height="Auto"/><br />
</Border><br />
<ControlTemplate.Triggers><br />
<Trigger Property="IsKeyboardFocused" Value="true"/><br />
<Trigger Property="ToggleButton.IsChecked" Value="true"/><br />
<Trigger Property="IsEnabled" Value="false"><br />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/><br />
</Trigger><br />
</ControlTemplate.Triggers><br />
</ControlTemplate><br />
</Setter.Value><br />
</Setter><br />
</Style>
And to use the style on the button
<br />
<Button HorizontalAlignment="Left" Margin="128,124,0,0" Style="{DynamicResource GradientButton}" VerticalAlignment="Top" Width="128" Height="56" Content="Nice Button"/><br />
How simple is that
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
I have tried using this to see the result in VS.NET 2005 without any success.
Please can you email me the xaml file so that I could compare the results?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul,
You will need to the WPF extensions for visual studio of course.
If you have those installed, simply create a new WPF Window, say Window1.xaml
and past the following code into it.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="UntitledProject1.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle SnapsToDevicePixels="true" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="3"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFFFFF" Offset="0"/>
<GradientStop Color="#FFF0F0EA" Offset="0.9"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
<Style x:Key="GradientButton" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Width="Auto" Height="Auto" BorderBrush="#FF3F3F9A" BorderThickness="2,2,2,2" CornerRadius="5,5,5,5">
<Border.Background>
<LinearGradientBrush EndPoint="0.92,0.266" StartPoint="0.92,1.409">
<GradientStop Color="#FF14252E" Offset="0"/>
<GradientStop Color="#FFB0E3FE" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<ContentPresenter HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center" Width="Auto" Height="Auto"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true"/>
<Trigger Property="ToggleButton.IsChecked" Value="true"/>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Button HorizontalAlignment="Left" Margin="128,124,0,0" Style="{DynamicResource GradientButton}" VerticalAlignment="Top" Width="128" Height="56" Content="Nice Button"/> </Grid>
</Window>
If you want a full project, email me at sachabarber@hotmail.com, and ill send it to you
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
Thank you.
I have the WPF extensions for visual studio installed, and have the Expression Blend/Web - just cannot do any good artistic work
I wanted to see how you produced that effect that required the PathGradientBrush
of the GDI+.
Okay, I have verified it, and as I thought it never produced the RibbonRoundButton
button but just a simple gradient button!
In GDI+, you can get that with a simplier and smaller code!
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|