1
// ------------------------------------------------------------------
2 // Copyright (C) 2011-2014 Maruko Toolbox Project
4 // Authors: LunarShaddow <aflyhorse@hotmail.com>
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15 // express or implied.
16 // See the License for the specific language governing permissions
17 // and limitations under the License.
18 // -------------------------------------------------------------------
22 using System
.Collections
.Generic
;
23 using System
.ComponentModel
;
25 using System
.Windows
.Forms
;
33 /// A wrapper to make Invoke more easy by using Method Extension.
37 public static void InvokeIfRequired(this ISynchronizeInvoke control
, MethodInvoker action
)
39 if (control
.InvokeRequired
)
40 control
.Invoke(action
, null);
47 /// Handmade progress bar. Currently not in use.
49 class ProgressBarEx
: ProgressBar
51 public ProgressBarEx()
53 // Modify the ControlStyles flags
54 //http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx
55 SetStyle(ControlStyles
.UserPaint
| ControlStyles
.AllPaintingInWmPaint
, true);
56 // Initialize Property
58 Format
= new StringFormat(StringFormatFlags
.NoWrap
);
59 Format
.Alignment
= StringAlignment
.Center
;
60 Format
.LineAlignment
= StringAlignment
.Center
;
63 public String CustomText { get; set; }
65 private StringFormat Format { get; set; }
67 protected override void OnPaint(PaintEventArgs e
)
69 // let the system do base work first
72 var rect
= ClientRectangle
;
74 // draw the background
75 ProgressBarRenderer
.DrawHorizontalBar(g
, rect
);
80 Rectangle clip
= new Rectangle(rect
.X
, rect
.Y
, Value
* rect
.Width
/ Maximum
, rect
.Height
);
81 ProgressBarRenderer
.DrawHorizontalChunks(g
, clip
);
84 g
.DrawString(CustomText
, SystemFonts
.DefaultFont
, SystemBrushes
.ControlText
,
85 this.DisplayRectangle
, Format
);