Changeset 230
- Timestamp:
- 3/11/2008 10:15:07 AM (5 years ago)
- Location:
- branches/eraser6
- Files:
-
- 4 edited
-
Eraser/ProgressForm.Designer.cs (modified) (1 diff)
-
Eraser/ProgressForm.cs (modified) (3 diffs)
-
Util/File.cs (modified) (2 diffs)
-
Util/Util.csproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser/ProgressForm.Designer.cs
r220 r230 108 108 // item 109 109 // 110 this.item.AutoSize = true;111 110 this.item.Location = new System.Drawing.Point(215, 61); 112 111 this.item.Name = "item"; 113 this.item.Size = new System.Drawing.Size( 71, 15);112 this.item.Size = new System.Drawing.Size(220, 15); 114 113 this.item.TabIndex = 7; 115 114 this.item.Text = "C:\\...\\File.txt"; -
branches/eraser6/Eraser/ProgressForm.cs
r220 r230 8 8 9 9 using Eraser.Manager; 10 using Eraser.Util; 10 11 11 12 namespace Eraser … … 42 43 } 43 44 44 item.Text = e.CurrentItemName;45 item.Text = File.GetCompactPath(e.CurrentItemName, item.Width, item.Font); 45 46 pass.Text = string.Format("{0} out of {1}", e.CurrentPass, e.TotalPasses); 46 47 timeLeft.Text = string.Format("{0} left", new TimeSpan(0, 0, e.TimeLeft).ToString()); … … 81 82 break; 82 83 } 84 85 //Change the Stop button to be a Close button. 86 stop.Text = "Close"; 83 87 } 84 88 -
branches/eraser6/Util/File.cs
r135 r230 4 4 5 5 using System.Runtime.InteropServices; 6 using System.Windows.Forms; 6 7 using System.Drawing; 7 8 … … 42 43 return Icon.FromHandle(shfi.hIcon); 43 44 } 45 46 public static string GetCompactPath(string longPath, int newWidth, Font drawFont) 47 { 48 using (Control ctrl = new Control()) 49 { 50 //First check if the source string is too long. 51 Graphics g = ctrl.CreateGraphics(); 52 int width = g.MeasureString(longPath, drawFont).ToSize().Width; 53 if (width <= newWidth) 54 return longPath; 55 56 //It is, shorten it. 57 int aveCharWidth = width / longPath.Length; 58 int charCount = newWidth / aveCharWidth; 59 StringBuilder builder = new StringBuilder(); 60 builder.Append(longPath); 61 builder.EnsureCapacity(charCount); 62 63 while (g.MeasureString(builder.ToString(), drawFont).Width > newWidth) 64 { 65 if (PathCompactPathEx(builder, longPath, (UIntPtr)(--charCount), 66 (UIntPtr)0) == UIntPtr.Zero) 67 { 68 return string.Empty; 69 } 70 } 71 72 return builder.ToString(); 73 } 74 } 75 76 /// <summary> 77 /// Truncates a path to fit within a certain number of characters by 78 /// replacing path components with ellipses. 79 /// </summary> 80 /// <param name="pszOut">[out] The address of the string that has been altered.</param> 81 /// <param name="pszSrc">[in] A pointer to a null-terminated string of maximum 82 /// length MAX_PATH that contains the path to be altered.</param> 83 /// <param name="cchMax">[in] The maximum number of characters to be 84 /// contained in the new string, including the terminating NULL character. 85 /// For example, if cchMax = 8, the resulting string can contain a maximum 86 /// of 7 characters plus the terminating NULL character.</param> 87 /// <param name="dwFlags">Reserved.</param> 88 /// <returns>Returns TRUE if successful, or FALSE otherwise.</returns> 89 [DllImport("Shlwapi.dll")] 90 private static extern UIntPtr PathCompactPathEx( 91 StringBuilder pszOut, string pszSrc, UIntPtr cchMax, UIntPtr dwFlags); 44 92 45 93 /// <summary> -
branches/eraser6/Util/Util.csproj
r167 r230 32 32 <Reference Include="System.Data" /> 33 33 <Reference Include="System.Drawing" /> 34 <Reference Include="System.Windows.Forms" /> 34 35 <Reference Include="System.Xml" /> 35 36 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.
