У меня есть текстовый файл, который содержит информацию о шрифте, как это:
Arial, 12,5
... и мне нужно прочитать эту информацию на этикетке. Шрифт так:
label.Font = new Font (fontNameFields [0], Single.Parse (fontNameFields [1]));
... но я всегда получаю следующую ошибку:
Индекс находился за пределами массива.
Может кто-нибудь помочь мне с этим?
Спасибо
Джейсон.
Код у меня есть:
MatchCollection lines = Regex.Matches(File.ReadAllText(Path), @"(.+?)\r\n""([^""]+)""\r\n(\d+), (\d+)");
foreach (Match match in lines)
{
string control = match.Groups[1].Value;
string text = match.Groups[2].Value;
int x = Int32.Parse(match.Groups[3].Value);
int y = Int32.Parse(match.Groups[4].Value);
String cfont = match.Groups[5].Value;
String fontName = cfont;
String[] fontNameFields = fontName.Split(',');
label.Font = new Font(fontNameFields[0], Single.Parse(fontNameFields[1]));
}
StackTrace
at Tabbed.Form1.FillCanvas() in C:\Documents and Settings\jay\My Documents\Visual Studio 2008\Projects\MYPROGGY\ MYPROGGY\Form1.cs:line 574
at Tabbed.Form1.openbtn_Click(Object sender, EventArgs e) in C:\Documents and Settings\jay\My Documents\Visual Studio 2008\Projects\ MYPROGGY\ MYPROGGY\Form1.cs:line 802
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Tabbed.Program.Main(String[] args) in C:\Documents and Settings\jay\My Documents\Visual Studio 2008\Projects\ MYPROGGY\ MYPROGGY\Program.cs:line 27
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()