|
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.
|
|
|
|
|
Yeah that may be the case for this example. I know in GDI there is a LinearGradientBrush, thats fine. My point was that XAML/WPF is truly amazing and you can do so much more with it then GDI+.
Thats all I meant. Its trivial to do cool stuff
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
Thank you, I understand your point.
I, however, do not think a company will invest its money to develop XAML
application.
For a rapidly changing systems like Web development, it might make sense
but then Silverlight/Flash etc is there
That the Wii won over PS3/XBox360 gives a good example of "cool graphics not
always the best/only solution".
Anyway, thanks for the support and the time.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote: For a rapidly changing systems like Web development, it might make sense
but then Silverlight/Flash etc is there
I just went to a SilverLight training course at Microsoft, and would not touch it with a barg pole at the moment. I have used Flash a fair ammount so can see the difference, Flash is way better IMHO.
WPF on the other hand is so cool, and there is nothing like it apart from Flex. But Flex still uses action script 3.0, and WPF uses C# or VB (the full set of classes and all), this is why WPF is better than both Flash and SilverLight.
Flash is better than SilverLight because its easier and more powerful
WPF is better than Flex because its easier and more powerful
Those are my 2 cents and way
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
Thanks for the reply and the information.
I wish you could give out some of the weakness of the Silverlight.
For my current project, I have no choice - I give the users what they want and try
to be ahead of the competition (and that will mean supporting Flex, Silvelight,
WPF, PDF, JavaFX etc).
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote: For my current project, I have no choice - I give the users what they want and try
to be ahead of the competition (and that will mean supporting Flex, Silvelight,
WPF, PDF, JavaFX etc).
Sounds like a very interesting project.
Where are you based?
Ok as far as Silverlight vs Flash.
Flash has full OO action script that supports video, tweens, vector animation manipulation, XML parsing, IO handling. Basically it's very mature language these days.
Silverlight Alpha (the one out now) is Javascript only object model, no .NET CLR support at all. So you simply can't compare the functionality available with Silverlight Alpha with Flash. Flash wins hands down. As I prefer Action script to javascript any day of the week. From what we saw of Silverlight Alpha, its was just quite clunky and didnt look that usable, Mike Ormond (MSFT man, kept saying cant do this at this version, but next one youll be able to). Flash on the other hand is easy to use, loads of resources tutorials available, right now.
Silverlight Beta (1.1 apparently) will have CLR support, but will run in a sandbox, basically a safe cutdown CLR enviroment, it remains to be seen just what will and wont be allowed. If Microsoft go completely security mad, they could end up with something like a Java Applet, which is very very limited, perhaps too limited for most interesting apps. If they open the security too wide, theyll end up with something that could do activeX type activities, such as delete or create files. This could be bad for a internet user. Remember Microsoft have released a plugin that stops ActiveX until the user confirms they are allowed for the given page. This is their own technology being stopped by them. Thats bad.
I just think at this moment in time Flash is the better system, its model just works.
Like I say I think, WPF proper, is totally different, and seems fairly mature already. Silverlight just doesnt seem ready yet.
But if you want to be ahead of the game, go for it.
Anyways thats just my opinion, who am I to say.
Sacha Barber
A Modern Geek - I cook, I clean, I drink, I Program. Modern or what?
My Blog : sachabarber.net
|
|
|
|
|
Thanks so much.
Sacha Barber wrote: Sounds like a very interesting project.
It should be but the work load is too heavy
Sacha Barber wrote: Where are you based?
I work for a small company here in Japan. We are initially doing factory/fault management systems for companies here, but decided to expand some of the components for sale.
Just a note...the alpha is 1.1, but beta which is out is 1.0.
I really appreciate you taking the time to explain all these. The analysis is
good, and very educative.
Sacha Barber wrote: Anyways thats just my opinion, who am I to say.
It is a great help, and I really like it.
Best regards,
Paul.
-- modified at 8:46 Monday 18th June, 2007
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|