本帖最后由 mindrayguowei 于 2016-4-20 11:51 编辑
为了通过HypertextLink来实现点击一下HypertextLink内容来实现下拉修改HypertextLink的值的功能, 添加了一个TextFieldClicked事件, 点击以下会弹出一个combobox, 通过combobox来选择相应的值, 并设置到HypertextLink里去, 但是遇到很严重的程序崩溃问题, 部署到客户的电脑上后,频繁的出现偶发的系统崩溃, 异常无法捕捉到. 但是在开发环境里面无法重现该问题.
以下是代码
- void _textControl_TextFieldClicked(object sender, TextFieldEventArgs e)
- {
- if (_textControl.EditMode == TXTextControl.EditMode.ReadOnly)
- {
- return;
- }
- try
- {
- HypertextLink textLink = e.TextField as HypertextLink;
-
- if (textLink != null)
- {
- string[] strArray = textLink.Target.Split(";".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
- if (strArray.Length == 1)
- {
- _textControl.Select(textLink.Start - 1, textLink.Length);
- return;
- }
- //if (Array.IndexOf(strArray, textLink.Text) == -1)
- //{
- // _textControl.Select(textLink.Start - 1, textLink.Length);
- // return;
- //}
- _textControl.Controls.Clear();
- ComboBox comboBox = new ComboBox();
- comboBox.Items.AddRange(strArray);
- int left = (textLink.Bounds.Location.X - _textControl.ScrollLocation.X) / TwipsPerPixel * _textControl.ZoomFactor / 100;
- int top = (textLink.Bounds.Location.Y - _textControl.ScrollLocation.Y) / TwipsPerPixel * _textControl.ZoomFactor / 100;
- System.Drawing.Point cbLocation = new System.Drawing.Point(left, top);
- comboBox.Location = cbLocation;
- comboBox.DropDownStyle = ComboBoxStyle.Simple;
- comboBox.BackColor = System.Drawing.Color.FromArgb(255, 255, 192);
- string maxString = string.Empty;
- Array.ForEach<string>(strArray, delegate(string str) { if (str.Trim().Length > maxString.Length) maxString = str; });
- System.Drawing.Graphics graphics = _textControl.CreateGraphics();
- System.Drawing.SizeF sizef = graphics.MeasureString(maxString, _textControl.Font);
- comboBox.Width = (int)Math.Ceiling(sizef.Width) + 30;
- comboBox.SelectedText = textLink.Text;
- _textControl.Controls.Add(comboBox);
- comboBox.Focus();
- _currentTextlink = textLink;
- comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
- comboBox.LostFocus += new EventHandler(comboBox_LostFocus);
- }
- }
- catch (Exception ex)
- {
- LogAdapter.LogError("_textControl_TextFieldClicked:" + ex.Message);
- }
- }
- void comboBox_LostFocus(object sender, EventArgs e)
- {
- try
- {
- if (_currentTextlink == null) return;
- ComboBox combobox = sender as ComboBox;
- if (combobox.SelectedItem == null)
- {
- _currentTextlink.Text = ((ComboBox)sender).Text;
- }
- else
- {
- _currentTextlink.Text = ((ComboBox)sender).SelectedItem.ToString();
- }
- _documentDirty = true;
- }
- catch (Exception ex)
- {
- LogAdapter.LogError("comboBox_LostFocus:" + ex.Message);
- }
- finally
- {
- try
- {
- _currentTextlink = null;
- _textControl.Controls.Clear();
- }
- catch
- { }
- }
- }
- void comboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- if (_currentTextlink == null) return;
- ComboBox combobox = sender as ComboBox;
- if (combobox.SelectedItem == null)
- {
- _currentTextlink.Text = ((ComboBox)sender).Text;
- }
- else
- {
- _currentTextlink.Text = ((ComboBox)sender).SelectedItem.ToString();
- }
- _documentDirty = true;
- }
- catch (Exception ex)
- {
- LogAdapter.LogError("comboBox_SelectedIndexChanged:" + ex.Message);
- }
- finally
- {
- try
- {
- _currentTextlink = null;
- _textControl.Controls.Clear();
- }
- catch
- { }
- }
- }
复制代码
以下是输出的dump文件在windbg里面的信息, 生产环境是windows 8.1 x64, 在某些windows 7 64位和32位下也都会报错,编译环境是32位程序, 没有拿到symbol文件, 调试不下去了
Loading unloaded module list
.....
eax=00000000 ebx=00000000 ecx=00000000 edx=00000000 esi=00000003 edi=00000003
eip=773fc7ec esp=00d0d3b8 ebp=00d0d540 iopl=0 nv up ei pl nz na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00200206
*** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdll.dll -
ntdll!NtWaitForMultipleObjects+0xc:
773fc7ec c21400 ret 14h
|
|